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}
This commit is contained in:
adamk 2015-07-21 10:16:57 -07:00 committed by Commit bot
parent 4829bbc5d1
commit 4b8200078a
19 changed files with 31 additions and 98 deletions

View File

@ -116,9 +116,7 @@ function testDone(iteration) {
} }
var iteration = iteration || 0; var iteration = iteration || 0;
var dummy = {}; %EnqueueMicrotask(checkResult);
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(); testDone();

View File

@ -63,10 +63,7 @@ function testDone(iteration) {
} }
} }
// Run testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -77,10 +77,7 @@ function testDone(iteration) {
} }
} }
// Run testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -60,10 +60,7 @@ function testDone(iteration) {
} }
} }
// Run testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -67,10 +67,7 @@ function testDone(iteration) {
} }
} }
// Run testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -60,10 +60,7 @@ function testDone(iteration) {
} }
} }
// Run testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -66,10 +66,7 @@ function testDone(iteration) {
} }
} }
// Run testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -78,10 +78,7 @@ function testDone(iteration) {
} }
} }
// Run testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -66,10 +66,7 @@ function testDone(iteration) {
} }
} }
// Run testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -62,10 +62,7 @@ function testDone(iteration) {
} }
} }
// Run testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -78,10 +78,7 @@ function testDone(iteration) {
} }
} }
// Run testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -61,10 +61,7 @@ function testDone(iteration) {
} }
} }
// Rerun testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -61,10 +61,7 @@ function testDone(iteration) {
} }
} }
// Run testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -81,10 +81,7 @@ function testDone(iteration) {
} }
} }
// Run testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -79,10 +79,7 @@ function testDone(iteration) {
} }
} }
// Run testDone through the Object.observe processing loop. %EnqueueMicrotask(checkResult);
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
} }
testDone(0); testDone(0);

View File

@ -29,7 +29,6 @@
// Make sure we don't rely on functions patchable by monkeys. // Make sure we don't rely on functions patchable by monkeys.
var call = Function.prototype.call.call.bind(Function.prototype.call) var call = Function.prototype.call.call.bind(Function.prototype.call)
var observe = Object.observe;
var getOwnPropertyNames = Object.getOwnPropertyNames; var getOwnPropertyNames = Object.getOwnPropertyNames;
var defineProperty = Object.defineProperty; var defineProperty = Object.defineProperty;
var numberPrototype = Number.prototype; var numberPrototype = Number.prototype;
@ -87,19 +86,15 @@ function assertAsync(b, s) {
} }
function assertAsyncDone(iteration) { function assertAsyncDone(iteration) {
var iteration = iteration || 0 var iteration = iteration || 0;
var dummy = {} %EnqueueMicrotask(function() {
observe(dummy,
function() {
if (asyncAssertsExpected === 0) if (asyncAssertsExpected === 0)
assertAsync(true, "all") assertAsync(true, "all")
else if (iteration > 10) // Shouldn't take more. else if (iteration > 10) // Shouldn't take more.
assertAsync(false, "all") assertAsync(false, "all")
else else
assertAsyncDone(iteration + 1) assertAsyncDone(iteration + 1)
} });
)
dummy.dummy = dummy
} }

View File

@ -33,15 +33,6 @@ var clearTimeout;
var timers = {}; var timers = {};
var currentId = 0; 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) { setInterval = function(fn, delay) {
var i = 0; var i = 0;
var id = currentId++; var id = currentId++;
@ -52,9 +43,9 @@ setInterval = function(fn, delay) {
if (i++ >= delay) { if (i++ >= delay) {
fn(); fn();
} }
PostMicrotask(loop); %EnqueueMicrotask(loop);
} }
PostMicrotask(loop); %EnqueueMicrotask(loop);
timers[id] = true; timers[id] = true;
return id; return id;
} }

View File

@ -41,15 +41,6 @@ var assert = require('assert');
(function() { (function() {
var TIMEOUT = 1000; var TIMEOUT = 1000;
function PostMicrotask(fn) {
var o = {};
Object.observe(o, function() {
fn();
});
// Change something to enqueue a microtask.
o.x = 'hello';
}
var context = { var context = {
beingDescribed: undefined, beingDescribed: undefined,
currentSuiteIndex: 0, currentSuiteIndex: 0,
@ -162,7 +153,7 @@ TestCase.prototype.Run = function(suite, postAction) {
if (this.isRegular) { if (this.isRegular) {
print('PASS: ' + suite.description + '#' + this.name); print('PASS: ' + suite.description + '#' + this.name);
} }
PostMicrotask(postAction); %EnqueueMicrotask(postAction);
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
@ -194,14 +185,14 @@ function TestSuite(described) {
TestSuite.prototype.Run = function() { TestSuite.prototype.Run = function() {
this.hasRun = this.currentIndex === this.cases.length; this.hasRun = this.currentIndex === this.cases.length;
if (this.hasRun) { if (this.hasRun) {
PostMicrotask(Run); %EnqueueMicrotask(Run);
return; return;
} }
// TestCase.prototype.Run cannot throw an exception. // TestCase.prototype.Run cannot throw an exception.
this.cases[this.currentIndex].Run(this, function() { this.cases[this.currentIndex].Run(this, function() {
++this.currentIndex; ++this.currentIndex;
PostMicrotask(Run); %EnqueueMicrotask(Run);
}.bind(this)); }.bind(this));
}; };
@ -224,7 +215,7 @@ TestSuite.prototype.ReportError = function(testCase, e) {
print('FAIL: ' + this.description + '#' + testCase.name + ': ' + print('FAIL: ' + this.description + '#' + testCase.name + ': ' +
e.name + ' (' + e.message + ')'); e.name + ' (' + e.message + ')');
++this.currentIndex; ++this.currentIndex;
PostMicrotask(Run); %EnqueueMicrotask(Run);
}; };
describe = function(description, fn) { describe = function(description, fn) {

View File

@ -77,7 +77,7 @@ class PromiseAplusTestSuite(testsuite.TestSuite):
if fname.endswith('.js')] if fname.endswith('.js')]
def GetFlagsForTestCase(self, testcase, context): 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 + self.helper_files_pre +
[os.path.join(self.test_files_root, testcase.path + '.js')] + [os.path.join(self.test_files_root, testcase.path + '.js')] +
self.helper_files_post) self.helper_files_post)