Commit 4b820007 authored by adamk's avatar adamk Committed by Commit bot

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}
parent 4829bbc5
...@@ -116,9 +116,7 @@ function testDone(iteration) { ...@@ -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();
...@@ -63,10 +63,7 @@ function testDone(iteration) { ...@@ -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);
...@@ -77,10 +77,7 @@ function testDone(iteration) { ...@@ -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);
...@@ -60,10 +60,7 @@ function testDone(iteration) { ...@@ -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);
...@@ -67,10 +67,7 @@ function testDone(iteration) { ...@@ -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);
...@@ -60,10 +60,7 @@ function testDone(iteration) { ...@@ -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);
...@@ -66,10 +66,7 @@ function testDone(iteration) { ...@@ -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);
......
...@@ -78,10 +78,7 @@ function testDone(iteration) { ...@@ -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);
...@@ -66,10 +66,7 @@ function testDone(iteration) { ...@@ -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);
......
...@@ -62,10 +62,7 @@ function testDone(iteration) { ...@@ -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);
...@@ -78,10 +78,7 @@ function testDone(iteration) { ...@@ -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);
...@@ -61,10 +61,7 @@ function testDone(iteration) { ...@@ -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);
...@@ -61,10 +61,7 @@ function testDone(iteration) { ...@@ -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);
...@@ -81,10 +81,7 @@ function testDone(iteration) { ...@@ -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);
...@@ -79,10 +79,7 @@ function testDone(iteration) { ...@@ -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);
...@@ -29,7 +29,6 @@ ...@@ -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) { ...@@ -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
} }
......
...@@ -33,15 +33,6 @@ var clearTimeout; ...@@ -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) { ...@@ -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;
} }
......
...@@ -41,15 +41,6 @@ var assert = require('assert'); ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) {
......
...@@ -77,7 +77,7 @@ class PromiseAplusTestSuite(testsuite.TestSuite): ...@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment