From: rossberg@chromium.org Date: Fri, 13 Sep 2013 08:09:39 +0000 (+0000) Subject: Allow implicit conversion of acceptList values to string during Object.observe X-Git-Tag: upstream/4.7.83~12513 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f99298bf5dc58c84db8fa329b4cd13704fee6444;p=platform%2Fupstream%2Fv8.git Allow implicit conversion of acceptList values to string during Object.observe R=rossberg@chromium.org BUG= Review URL: https://codereview.chromium.org/23464058 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16703 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/object-observe.js b/src/object-observe.js index 1035792..b09c42d 100644 --- a/src/object-observe.js +++ b/src/object-observe.js @@ -284,11 +284,6 @@ function AcceptArgIsValid(arg) { arg.length < 0) return false; - var length = arg.length; - for (var i = 0; i < length; i++) { - if (!IS_STRING(arg[i])) - return false; - } return true; } diff --git a/test/mjsunit/harmony/object-observe.js b/test/mjsunit/harmony/object-observe.js index 75f0ff8..e068742 100644 --- a/test/mjsunit/harmony/object-observe.js +++ b/test/mjsunit/harmony/object-observe.js @@ -110,14 +110,16 @@ Object.defineProperty(changeRecordWithAccessor, 'name', { // Object.observe -assertThrows(function() { Object.observe("non-object", observer.callback); }, TypeError); +assertThrows(function() { Object.observe("non-object", observer.callback); }, + TypeError); assertThrows(function() { Object.observe(obj, nonFunction); }, TypeError); assertThrows(function() { Object.observe(obj, frozenFunction); }, TypeError); -assertThrows(function() { Object.observe(obj, function() {}, 1); }, TypeError); -assertThrows(function() { Object.observe(obj, function() {}, [undefined]); }, TypeError); -assertThrows(function() { Object.observe(obj, function() {}, [1]); }, TypeError); -assertThrows(function() { Object.observe(obj, function() {}, ['foo', null]); }, TypeError); -assertEquals(obj, Object.observe(obj, observer.callback, ['foo', 'bar', 'baz'])); +assertEquals(obj, Object.observe(obj, observer.callback, [1])); +assertEquals(obj, Object.observe(obj, observer.callback, [true])); +assertEquals(obj, Object.observe(obj, observer.callback, ['foo', null])); +assertEquals(obj, Object.observe(obj, observer.callback, [undefined])); +assertEquals(obj, Object.observe(obj, observer.callback, + ['foo', 'bar', 'baz'])); assertEquals(obj, Object.observe(obj, observer.callback, [])); assertEquals(obj, Object.observe(obj, observer.callback, undefined)); assertEquals(obj, Object.observe(obj, observer.callback)); @@ -202,6 +204,25 @@ observer.assertCallbackRecords([ { object: obj, name: 'bar', type: 'deleted', expando2: 'str' } ]); +// Non-string accept values are coerced to strings +reset(); +Object.observe(obj, observer.callback, [true, 1, null, undefined]); +notifier = Object.getNotifier(obj); +notifier.notify({ type: 'true' }); +notifier.notify({ type: 'false' }); +notifier.notify({ type: '1' }); +notifier.notify({ type: '-1' }); +notifier.notify({ type: 'null' }); +notifier.notify({ type: 'nill' }); +notifier.notify({ type: 'undefined' }); +notifier.notify({ type: 'defined' }); +Object.deliverChangeRecords(observer.callback); +observer.assertCallbackRecords([ + { object: obj, type: 'true' }, + { object: obj, type: '1' }, + { object: obj, type: 'null' }, + { object: obj, type: 'undefined' } +]); // No delivery takes place if no records are pending reset(); @@ -307,7 +328,7 @@ observer.assertCallbackRecords([ // Accept reset(); -Object.observe(obj, observer.callback, []); +Object.observe(obj, observer.callback, ['somethingElse']); Object.getNotifier(obj).notify({ type: 'new' });