diff --git a/harness/sm/non262-generators-shell.js b/harness/sm/non262-generators-shell.js index 46161a803c..ece16e815b 100644 --- a/harness/sm/non262-generators-shell.js +++ b/harness/sm/non262-generators-shell.js @@ -10,7 +10,7 @@ function assertFalse(a) { assertEq(a, false) } function assertTrue(a) { assertEq(a, true) } function assertNotEq(found, not_expected) { assertEq(Object.is(found, not_expected), false) } function assertIteratorResult(result, value, done) { - assertDeepEq(result.value, value); + assert.deepEqual(result.value, value); assertEq(result.done, done); } function assertIteratorNext(iter, value) { diff --git a/harness/sm/non262-shell.js b/harness/sm/non262-shell.js index f124b34057..11fa3f23d2 100644 --- a/harness/sm/non262-shell.js +++ b/harness/sm/non262-shell.js @@ -188,190 +188,4 @@ allow_unused: True } } - globalThis.assertDeepEq = (function(){ - var call = Function.prototype.call, - Array_isArray = Array.isArray, - Array_includes = call.bind(Array.prototype.includes), - Map_ = Map, - Error_ = Error, - Symbol_ = Symbol, - Symbol_keyFor = Symbol.keyFor, - Symbol_description = call.bind(Object.getOwnPropertyDescriptor(Symbol.prototype, "description").get), - Map_has = call.bind(Map.prototype.has), - Map_get = call.bind(Map.prototype.get), - Map_set = call.bind(Map.prototype.set), - Object_toString = call.bind(Object.prototype.toString), - Function_toString = call.bind(Function.prototype.toString), - Object_getPrototypeOf = Object.getPrototypeOf, - Object_hasOwnProperty = call.bind(Object.prototype.hasOwnProperty), - Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, - Object_isExtensible = Object.isExtensible, - Object_getOwnPropertyNames = Object.getOwnPropertyNames; - - // Return true iff ES6 Type(v) isn't Object. - // Note that `typeof document.all === "undefined"`. - function isPrimitive(v) { - return (v === null || - v === undefined || - typeof v === "boolean" || - typeof v === "number" || - typeof v === "string" || - typeof v === "symbol"); - } - - function assertSameValue(a, b, msg) { - try { - assertEq(a, b); - } catch (exc) { - throw Error_(exc.message + (msg ? " " + msg : "")); - } - } - - function assertSameClass(a, b, msg) { - var ac = Object_toString(a), bc = Object_toString(b); - assertSameValue(ac, bc, msg); - switch (ac) { - case "[object Function]": - if (typeof isProxy !== "undefined" && !isProxy(a) && !isProxy(b)) - assertSameValue(Function_toString(a), Function_toString(b), msg); - } - } - - function at(prevmsg, segment) { - return prevmsg ? prevmsg + segment : "at _" + segment; - } - - // Assert that the arguments a and b are thoroughly structurally equivalent. - // - // For the sake of speed, we cut a corner: - // var x = {}, y = {}, ax = [x]; - // assertDeepEq([ax, x], [ax, y]); // passes (?!) - // - // Technically this should fail, since the two object graphs are different. - // (The graph of [ax, y] contains one more object than the graph of [ax, x].) - // - // To get technically correct behavior, pass {strictEquivalence: true}. - // This is slower because we have to walk the entire graph, and Object.prototype - // is big. - // - return function assertDeepEq(a, b, options) { - var strictEquivalence = options ? options.strictEquivalence : false; - - function assertSameProto(a, b, msg) { - check(Object_getPrototypeOf(a), Object_getPrototypeOf(b), at(msg, ".__proto__")); - } - - function failPropList(na, nb, msg) { - throw Error_("got own properties " + JSON.stringify(na) + ", expected " + JSON.stringify(nb) + - (msg ? " " + msg : "")); - } - - function assertSameProps(a, b, msg) { - var na = Object_getOwnPropertyNames(a), - nb = Object_getOwnPropertyNames(b); - if (na.length !== nb.length) - failPropList(na, nb, msg); - - // Ignore differences in whether Array elements are stored densely. - if (Array_isArray(a)) { - na.sort(); - nb.sort(); - } - - for (var i = 0; i < na.length; i++) { - var name = na[i]; - if (name !== nb[i]) - failPropList(na, nb, msg); - var da = Object_getOwnPropertyDescriptor(a, name), - db = Object_getOwnPropertyDescriptor(b, name); - var pmsg = at(msg, /^[_$A-Za-z0-9]+$/.test(name) - ? /0|[1-9][0-9]*/.test(name) ? "[" + name + "]" : "." + name - : "[" + JSON.stringify(name) + "]"); - assertSameValue(da.configurable, db.configurable, at(pmsg, ".[[Configurable]]")); - assertSameValue(da.enumerable, db.enumerable, at(pmsg, ".[[Enumerable]]")); - if (Object_hasOwnProperty(da, "value")) { - if (!Object_hasOwnProperty(db, "value")) - throw Error_("got data property, expected accessor property" + pmsg); - check(da.value, db.value, pmsg); - } else { - if (Object_hasOwnProperty(db, "value")) - throw Error_("got accessor property, expected data property" + pmsg); - check(da.get, db.get, at(pmsg, ".[[Get]]")); - check(da.set, db.set, at(pmsg, ".[[Set]]")); - } - } - }; - - const wellKnownSymbols = Reflect.ownKeys(Symbol) - .map(key => Symbol[key]) - .filter(value => typeof value === "symbol"); - - // The standard doesn't offer a convenient way to distinguish well-known - // symbols from user-created symbols. - function isSimilarSymbol(a, b) { - // Fast path for same symbols. - if (a === b) { - return true; - } - - // 1. Symbol descriptions must match. - // 2. Either both symbols are in the registry or none is. - // 3. Neither symbol must be a well-known symbol, because those are - // already handled through the fast path. - return Symbol_description(a) === Symbol_description(b) && - Symbol_keyFor(a) === Symbol_keyFor(b) && - !Array_includes(wellKnownSymbols, a) && - !Array_includes(wellKnownSymbols, b); - } - - var ab = new Map_(); - var bpath = new Map_(); - - function check(a, b, path) { - if (typeof a === "symbol") { - // Symbols are primitives, but they have identity. - // Symbol("x") !== Symbol("x") but - // assertDeepEq(Symbol("x"), Symbol("x")) should pass. - if (typeof b !== "symbol") { - throw Error_("got " + String(a) + ", expected " + String(b) + " " + path); - } else if (!isSimilarSymbol(a, b)) { - throw Error_("got " + String(a) + ", expected " + String(b) + " " + path); - } else if (Map_has(ab, a)) { - assertSameValue(Map_get(ab, a), b, path); - } else if (Map_has(bpath, b)) { - var bPrevPath = Map_get(bpath, b) || "_"; - throw Error_("got distinct symbols " + at(path, "") + " and " + - at(bPrevPath, "") + ", expected the same symbol both places"); - } else { - Map_set(ab, a, b); - Map_set(bpath, b, path); - } - } else if (isPrimitive(a)) { - assertSameValue(a, b, path); - } else if (isPrimitive(b)) { - throw Error_("got " + Object_toString(a) + ", expected " + String(b) + " " + path); - } else if (Map_has(ab, a)) { - assertSameValue(Map_get(ab, a), b, path); - } else if (Map_has(bpath, b)) { - var bPrevPath = Map_get(bpath, b) || "_"; - throw Error_("got distinct objects " + at(path, "") + " and " + at(bPrevPath, "") + - ", expected the same object both places"); - } else { - Map_set(ab, a, b); - Map_set(bpath, b, path); - if (a !== b || strictEquivalence) { - assertSameClass(a, b, path); - assertSameProto(a, b, path); - assertSameProps(a, b, path); - assertSameValue(Object_isExtensible(a), - Object_isExtensible(b), - at(path, ".[[Extensible]]")); - } - } - } - - check(a, b, ""); - }; - })(); - })(); diff --git a/test/staging/sm/generators/delegating-yield-12.js b/test/staging/sm/generators/delegating-yield-12.js index d7d17e8375..3d3cda963d 100644 --- a/test/staging/sm/generators/delegating-yield-12.js +++ b/test/staging/sm/generators/delegating-yield-12.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-generators-shell.js] +includes: [sm/non262.js, sm/non262-shell.js, sm/non262-generators-shell.js, deepEqual.js] flags: - noStrict description: | diff --git a/test/staging/sm/generators/delegating-yield-2.js b/test/staging/sm/generators/delegating-yield-2.js index 5b68adceae..ebb8b8230e 100644 --- a/test/staging/sm/generators/delegating-yield-2.js +++ b/test/staging/sm/generators/delegating-yield-2.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-generators-shell.js] +includes: [sm/non262.js, sm/non262-shell.js, sm/non262-generators-shell.js, deepEqual.js] flags: - noStrict description: | diff --git a/test/staging/sm/generators/delegating-yield-3.js b/test/staging/sm/generators/delegating-yield-3.js index 3d709df845..b2275d9772 100644 --- a/test/staging/sm/generators/delegating-yield-3.js +++ b/test/staging/sm/generators/delegating-yield-3.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-generators-shell.js] +includes: [sm/non262.js, sm/non262-shell.js, sm/non262-generators-shell.js, deepEqual.js] flags: - noStrict description: | diff --git a/test/staging/sm/generators/delegating-yield-4.js b/test/staging/sm/generators/delegating-yield-4.js index 44b8aba333..0c86af847b 100644 --- a/test/staging/sm/generators/delegating-yield-4.js +++ b/test/staging/sm/generators/delegating-yield-4.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-generators-shell.js] +includes: [sm/non262.js, sm/non262-shell.js, sm/non262-generators-shell.js, deepEqual.js] flags: - noStrict description: | diff --git a/test/staging/sm/generators/iteration.js b/test/staging/sm/generators/iteration.js index f209db59f9..365e179e39 100644 --- a/test/staging/sm/generators/iteration.js +++ b/test/staging/sm/generators/iteration.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-generators-shell.js] +includes: [sm/non262.js, sm/non262-shell.js, sm/non262-generators-shell.js, deepEqual.js] flags: - noStrict description: | diff --git a/test/staging/sm/generators/syntax.js b/test/staging/sm/generators/syntax.js index 043367de37..f49e5ec699 100644 --- a/test/staging/sm/generators/syntax.js +++ b/test/staging/sm/generators/syntax.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-generators-shell.js] +includes: [sm/non262.js, sm/non262-shell.js, sm/non262-generators-shell.js, deepEqual.js] flags: - noStrict description: |