From 4b8200078a9d1d9ec5bab268d0aff6453b47ddcc Mon Sep 17 00:00:00 2001 From: adamk Date: Tue, 21 Jul 2015 10:16:57 -0700 Subject: [PATCH] Remove unnecessary coupling between Promise tests and Object.observe Many mjsunit tests (as well as the promises-aplus adapter scripts) were using Object.observe simply for microtask-enqueueing purposes. Replaced such uses with %EnqueueMicrotask. Review URL: https://codereview.chromium.org/1246933002 Cr-Commit-Position: refs/heads/master@{#29779} --- test/mjsunit/es6/debug-promises/events.js | 4 +--- .../es6/debug-promises/reject-caught-all.js | 5 +--- ...reject-caught-by-default-reject-handler.js | 5 +--- .../es6/debug-promises/reject-uncaught-all.js | 5 +--- .../debug-promises/reject-uncaught-late.js | 5 +--- .../reject-uncaught-uncaught.js | 5 +--- .../reject-with-invalid-reject.js | 5 +--- .../reject-with-throw-in-reject.js | 5 +--- .../reject-with-undefined-reject.js | 5 +--- .../es6/debug-promises/throw-caught-all.js | 5 +--- .../throw-caught-by-default-reject-handler.js | 5 +--- .../es6/debug-promises/throw-uncaught-all.js | 5 +--- .../debug-promises/throw-uncaught-uncaught.js | 5 +--- .../throw-with-throw-in-reject.js | 5 +--- .../throw-with-undefined-reject.js | 5 +--- test/mjsunit/es6/promises.js | 23 ++++++++----------- test/promises-aplus/lib/global.js | 13 ++--------- test/promises-aplus/lib/mocha.js | 17 ++++---------- test/promises-aplus/testcfg.py | 2 +- 19 files changed, 31 insertions(+), 98 deletions(-) diff --git a/test/mjsunit/es6/debug-promises/events.js b/test/mjsunit/es6/debug-promises/events.js index a9f94543f4..3fcb22ff27 100644 --- a/test/mjsunit/es6/debug-promises/events.js +++ b/test/mjsunit/es6/debug-promises/events.js @@ -116,9 +116,7 @@ function testDone(iteration) { } var iteration = iteration || 0; - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(); diff --git a/test/mjsunit/es6/debug-promises/reject-caught-all.js b/test/mjsunit/es6/debug-promises/reject-caught-all.js index 0fca57730a..fd4770ebee 100644 --- a/test/mjsunit/es6/debug-promises/reject-caught-all.js +++ b/test/mjsunit/es6/debug-promises/reject-caught-all.js @@ -63,10 +63,7 @@ function testDone(iteration) { } } - // Run testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/debug-promises/reject-caught-by-default-reject-handler.js b/test/mjsunit/es6/debug-promises/reject-caught-by-default-reject-handler.js index 63151df016..b7c5861c1f 100644 --- a/test/mjsunit/es6/debug-promises/reject-caught-by-default-reject-handler.js +++ b/test/mjsunit/es6/debug-promises/reject-caught-by-default-reject-handler.js @@ -77,10 +77,7 @@ function testDone(iteration) { } } - // Run testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/debug-promises/reject-uncaught-all.js b/test/mjsunit/es6/debug-promises/reject-uncaught-all.js index beaf1878fe..0b0c0c8e38 100644 --- a/test/mjsunit/es6/debug-promises/reject-uncaught-all.js +++ b/test/mjsunit/es6/debug-promises/reject-uncaught-all.js @@ -60,10 +60,7 @@ function testDone(iteration) { } } - // Run testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/debug-promises/reject-uncaught-late.js b/test/mjsunit/es6/debug-promises/reject-uncaught-late.js index 4a883da13a..db58790e39 100644 --- a/test/mjsunit/es6/debug-promises/reject-uncaught-late.js +++ b/test/mjsunit/es6/debug-promises/reject-uncaught-late.js @@ -67,10 +67,7 @@ function testDone(iteration) { } } - // Run testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/debug-promises/reject-uncaught-uncaught.js b/test/mjsunit/es6/debug-promises/reject-uncaught-uncaught.js index 86e2a815e7..ac23b48b6f 100644 --- a/test/mjsunit/es6/debug-promises/reject-uncaught-uncaught.js +++ b/test/mjsunit/es6/debug-promises/reject-uncaught-uncaught.js @@ -60,10 +60,7 @@ function testDone(iteration) { } } - // Run testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/debug-promises/reject-with-invalid-reject.js b/test/mjsunit/es6/debug-promises/reject-with-invalid-reject.js index fc6233da8d..fa263458c4 100644 --- a/test/mjsunit/es6/debug-promises/reject-with-invalid-reject.js +++ b/test/mjsunit/es6/debug-promises/reject-with-invalid-reject.js @@ -66,10 +66,7 @@ function testDone(iteration) { } } - // Run testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/debug-promises/reject-with-throw-in-reject.js b/test/mjsunit/es6/debug-promises/reject-with-throw-in-reject.js index 15e464ec60..6b7dc1a77c 100644 --- a/test/mjsunit/es6/debug-promises/reject-with-throw-in-reject.js +++ b/test/mjsunit/es6/debug-promises/reject-with-throw-in-reject.js @@ -78,10 +78,7 @@ function testDone(iteration) { } } - // Run testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/debug-promises/reject-with-undefined-reject.js b/test/mjsunit/es6/debug-promises/reject-with-undefined-reject.js index d11c01ff73..4c57cf0237 100644 --- a/test/mjsunit/es6/debug-promises/reject-with-undefined-reject.js +++ b/test/mjsunit/es6/debug-promises/reject-with-undefined-reject.js @@ -66,10 +66,7 @@ function testDone(iteration) { } } - // Run testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/debug-promises/throw-caught-all.js b/test/mjsunit/es6/debug-promises/throw-caught-all.js index 2fbf05141d..bd6d343f82 100644 --- a/test/mjsunit/es6/debug-promises/throw-caught-all.js +++ b/test/mjsunit/es6/debug-promises/throw-caught-all.js @@ -62,10 +62,7 @@ function testDone(iteration) { } } - // Run testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/debug-promises/throw-caught-by-default-reject-handler.js b/test/mjsunit/es6/debug-promises/throw-caught-by-default-reject-handler.js index 36b5565e5f..3c30ad3f7c 100644 --- a/test/mjsunit/es6/debug-promises/throw-caught-by-default-reject-handler.js +++ b/test/mjsunit/es6/debug-promises/throw-caught-by-default-reject-handler.js @@ -78,10 +78,7 @@ function testDone(iteration) { } } - // Run testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/debug-promises/throw-uncaught-all.js b/test/mjsunit/es6/debug-promises/throw-uncaught-all.js index 72f800bf5b..c4bc6c44e3 100644 --- a/test/mjsunit/es6/debug-promises/throw-uncaught-all.js +++ b/test/mjsunit/es6/debug-promises/throw-uncaught-all.js @@ -61,10 +61,7 @@ function testDone(iteration) { } } - // Rerun testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/debug-promises/throw-uncaught-uncaught.js b/test/mjsunit/es6/debug-promises/throw-uncaught-uncaught.js index 69aa8ebbd2..ba82a1f8cb 100644 --- a/test/mjsunit/es6/debug-promises/throw-uncaught-uncaught.js +++ b/test/mjsunit/es6/debug-promises/throw-uncaught-uncaught.js @@ -61,10 +61,7 @@ function testDone(iteration) { } } - // Run testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/debug-promises/throw-with-throw-in-reject.js b/test/mjsunit/es6/debug-promises/throw-with-throw-in-reject.js index 1ea1c7f9ff..bd39a155cc 100644 --- a/test/mjsunit/es6/debug-promises/throw-with-throw-in-reject.js +++ b/test/mjsunit/es6/debug-promises/throw-with-throw-in-reject.js @@ -81,10 +81,7 @@ function testDone(iteration) { } } - // Run testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/debug-promises/throw-with-undefined-reject.js b/test/mjsunit/es6/debug-promises/throw-with-undefined-reject.js index 94dcdffa22..c88feb9c39 100644 --- a/test/mjsunit/es6/debug-promises/throw-with-undefined-reject.js +++ b/test/mjsunit/es6/debug-promises/throw-with-undefined-reject.js @@ -79,10 +79,7 @@ function testDone(iteration) { } } - // Run testDone through the Object.observe processing loop. - var dummy = {}; - Object.observe(dummy, checkResult); - dummy.dummy = dummy; + %EnqueueMicrotask(checkResult); } testDone(0); diff --git a/test/mjsunit/es6/promises.js b/test/mjsunit/es6/promises.js index 63b6d2f94a..19239b601b 100644 --- a/test/mjsunit/es6/promises.js +++ b/test/mjsunit/es6/promises.js @@ -29,7 +29,6 @@ // Make sure we don't rely on functions patchable by monkeys. var call = Function.prototype.call.call.bind(Function.prototype.call) -var observe = Object.observe; var getOwnPropertyNames = Object.getOwnPropertyNames; var defineProperty = Object.defineProperty; var numberPrototype = Number.prototype; @@ -87,19 +86,15 @@ function assertAsync(b, s) { } function assertAsyncDone(iteration) { - var iteration = iteration || 0 - var dummy = {} - observe(dummy, - function() { - if (asyncAssertsExpected === 0) - assertAsync(true, "all") - else if (iteration > 10) // Shouldn't take more. - assertAsync(false, "all") - else - assertAsyncDone(iteration + 1) - } - ) - dummy.dummy = dummy + var iteration = iteration || 0; + %EnqueueMicrotask(function() { + if (asyncAssertsExpected === 0) + assertAsync(true, "all") + else if (iteration > 10) // Shouldn't take more. + assertAsync(false, "all") + else + assertAsyncDone(iteration + 1) + }); } diff --git a/test/promises-aplus/lib/global.js b/test/promises-aplus/lib/global.js index 1466d2063b..ece338ed3e 100644 --- a/test/promises-aplus/lib/global.js +++ b/test/promises-aplus/lib/global.js @@ -33,15 +33,6 @@ var clearTimeout; var timers = {}; var currentId = 0; -function PostMicrotask(fn) { - var o = {}; - Object.observe(o, function() { - fn(); - }); - // Change something to enqueue a microtask. - o.x = 'hello'; -} - setInterval = function(fn, delay) { var i = 0; var id = currentId++; @@ -52,9 +43,9 @@ setInterval = function(fn, delay) { if (i++ >= delay) { fn(); } - PostMicrotask(loop); + %EnqueueMicrotask(loop); } - PostMicrotask(loop); + %EnqueueMicrotask(loop); timers[id] = true; return id; } diff --git a/test/promises-aplus/lib/mocha.js b/test/promises-aplus/lib/mocha.js index 24d294ef8f..0a172b9d2f 100644 --- a/test/promises-aplus/lib/mocha.js +++ b/test/promises-aplus/lib/mocha.js @@ -41,15 +41,6 @@ var assert = require('assert'); (function() { var TIMEOUT = 1000; -function PostMicrotask(fn) { - var o = {}; - Object.observe(o, function() { - fn(); - }); - // Change something to enqueue a microtask. - o.x = 'hello'; -} - var context = { beingDescribed: undefined, currentSuiteIndex: 0, @@ -162,7 +153,7 @@ TestCase.prototype.Run = function(suite, postAction) { if (this.isRegular) { print('PASS: ' + suite.description + '#' + this.name); } - PostMicrotask(postAction); + %EnqueueMicrotask(postAction); }.bind(this)); }.bind(this)); }.bind(this)); @@ -194,14 +185,14 @@ function TestSuite(described) { TestSuite.prototype.Run = function() { this.hasRun = this.currentIndex === this.cases.length; if (this.hasRun) { - PostMicrotask(Run); + %EnqueueMicrotask(Run); return; } // TestCase.prototype.Run cannot throw an exception. this.cases[this.currentIndex].Run(this, function() { ++this.currentIndex; - PostMicrotask(Run); + %EnqueueMicrotask(Run); }.bind(this)); }; @@ -224,7 +215,7 @@ TestSuite.prototype.ReportError = function(testCase, e) { print('FAIL: ' + this.description + '#' + testCase.name + ': ' + e.name + ' (' + e.message + ')'); ++this.currentIndex; - PostMicrotask(Run); + %EnqueueMicrotask(Run); }; describe = function(description, fn) { diff --git a/test/promises-aplus/testcfg.py b/test/promises-aplus/testcfg.py index bd03379187..5f447c3f90 100644 --- a/test/promises-aplus/testcfg.py +++ b/test/promises-aplus/testcfg.py @@ -77,7 +77,7 @@ class PromiseAplusTestSuite(testsuite.TestSuite): if fname.endswith('.js')] def GetFlagsForTestCase(self, testcase, context): - return (testcase.flags + context.mode_flags + ['--harmony'] + + return (testcase.flags + context.mode_flags + ['--allow-natives-syntax'] + self.helper_files_pre + [os.path.join(self.test_files_root, testcase.path + '.js')] + self.helper_files_post)