Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Unified Diff: test/mjsunit/es6/promises.js

Issue 366103005: Avoid brittle use of .bind in Promise.all (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Thorough test & rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/promise.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/es6/promises.js
diff --git a/test/mjsunit/es6/promises.js b/test/mjsunit/es6/promises.js
index 6dfe9261a858a3d658df84475feccce63d5a8aaa..faf154ee0a5f7c421bfd8e126f972ab2e31d37a7 100644
--- a/test/mjsunit/es6/promises.js
+++ b/test/mjsunit/es6/promises.js
@@ -27,6 +27,42 @@
// Flags: --allow-natives-syntax
+// 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
+
+function clear(o) {
+ if (o === null || (typeof o !== 'object' && typeof o !== 'function')) return
+ clear(o.__proto__)
+ var properties = getOwnPropertyNames(o)
+ for (var i in properties) {
+ clearProp(o, properties[i])
+ }
+}
+
+function clearProp(o, name) {
+ var poisoned = {caller: 0, callee: 0, arguments: 0}
+ try {
+ var x = o[name]
+ o[name] = undefined
+ clear(x)
+ } catch(e) {} // assertTrue(name in poisoned) }
+}
+
+// Find intrinsics and null them out.
+var globals = Object.getOwnPropertyNames(this)
+var whitelist = {Promise: true, TypeError: true}
+for (var i in globals) {
+ var name = globals[i]
+ if (name in whitelist || name[0] === name[0].toLowerCase()) delete globals[i]
+}
+for (var i in globals) {
+ if (globals[i]) clearProp(this, globals[i])
+}
+
+
var asyncAssertsExpected = 0;
function assertAsyncRan() { ++asyncAssertsExpected }
@@ -43,7 +79,7 @@ function assertAsync(b, s) {
function assertAsyncDone(iteration) {
var iteration = iteration || 0
var dummy = {}
- Object.observe(dummy,
+ observe(dummy,
function() {
if (asyncAssertsExpected === 0)
assertAsync(true, "all")
@@ -777,13 +813,13 @@ function assertAsyncDone(iteration) {
MyPromise.__proto__ = Promise
MyPromise.defer = function() {
log += "d"
- return this.__proto__.defer.call(this)
+ return call(this.__proto__.defer, this)
}
MyPromise.prototype.__proto__ = Promise.prototype
MyPromise.prototype.chain = function(resolve, reject) {
log += "c"
- return this.__proto__.__proto__.chain.call(this, resolve, reject)
+ return call(this.__proto__.__proto__.chain, this, resolve, reject)
}
log = ""
« no previous file with comments | « src/promise.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698