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) {
}
var iteration = iteration || 0;
var dummy = {};
Object.observe(dummy, checkResult);
dummy.dummy = dummy;
%EnqueueMicrotask(checkResult);
}
testDone();
......@@ -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);
......@@ -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);
......@@ -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);
......@@ -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);
......@@ -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);
......@@ -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);
......
......@@ -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);
......@@ -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);
......
......@@ -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);
......@@ -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);
......@@ -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);
......@@ -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);
......@@ -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);
......@@ -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);
......@@ -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)
});
}
......
......@@ -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;
}
......
......@@ -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) {
......
......@@ -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)
......
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