From 48b6a8baea405627867c3789d4e8fa034d8dc270 Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Fri, 21 Feb 2014 12:35:48 -0500 Subject: [PATCH] Backed out changeset 00d8b2e04b15 (bug 885788) for jit-test assertions. CLOSED TREE --- js/src/builtin/Object.cpp | 55 ---------- js/src/jit-test/tests/basic/setPrototypeOf.js | 102 ------------------ 2 files changed, 157 deletions(-) delete mode 100644 js/src/jit-test/tests/basic/setPrototypeOf.js diff --git a/js/src/builtin/Object.cpp b/js/src/builtin/Object.cpp index e1e67539612f..8e2689d3e167 100644 --- a/js/src/builtin/Object.cpp +++ b/js/src/builtin/Object.cpp @@ -539,60 +539,6 @@ obj_getPrototypeOf(JSContext *cx, unsigned argc, Value *vp) return true; } -static bool -obj_setPrototypeOf(JSContext *cx, unsigned argc, Value *vp) -{ - CallArgs args = CallArgsFromVp(argc, vp); - - RootedObject setPrototypeOf(cx, &args.callee()); - if (!GlobalObject::warnOnceAboutPrototypeMutation(cx, setPrototypeOf)) - return false; - - if (args.length() < 2) { - JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED, - "Object.setPrototypeOf", "1", ""); - return false; - } - - /* Step 1-2. */ - if (args[0].isNullOrUndefined()) { - JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_CANT_CONVERT_TO, - args[0].isNull() ? "null" : "undefined", "object"); - return false; - } - - /* Step 3. */ - if (!args[1].isObjectOrNull()) { - JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_NOT_EXPECTED_TYPE, - "Object.setPrototypeOf", "an object or null", InformalValueTypeName(args[1])); - return false; - } - - /* Step 4. */ - if (!args[0].isObject()) { - args.rval().set(args[0]); - return true; - } - - /* Step 5-6. */ - RootedObject obj(cx, &args[0].toObject()); - RootedObject newProto(cx, args[1].toObjectOrNull()); - - bool success; - if (!JSObject::setProto(cx, obj, newProto, &success)) - return false; - - /* Step 7. */ - if (!success) { - JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_OBJECT_NOT_EXTENSIBLE, "object"); - return false; - } - - /* Step 8. */ - args.rval().set(args[0]); - return true; -} - #if JS_HAS_OBJ_WATCHPOINT bool @@ -1068,7 +1014,6 @@ const JSFunctionSpec js::object_methods[] = { const JSFunctionSpec js::object_static_methods[] = { JS_FN("getPrototypeOf", obj_getPrototypeOf, 1,0), - JS_FN("setPrototypeOf", obj_setPrototypeOf, 2,0), JS_FN("getOwnPropertyDescriptor", obj_getOwnPropertyDescriptor,2,0), JS_FN("keys", obj_keys, 1,0), JS_FN("is", obj_is, 2,0), diff --git a/js/src/jit-test/tests/basic/setPrototypeOf.js b/js/src/jit-test/tests/basic/setPrototypeOf.js deleted file mode 100644 index c5ac67148b3c..000000000000 --- a/js/src/jit-test/tests/basic/setPrototypeOf.js +++ /dev/null @@ -1,102 +0,0 @@ -load(libdir + 'asserts.js'); - -function getObjects() { - function func(){} - return [func, - new func(), - {x: 5}, - /regexp/, - [1, 2, 3], - new Date(), - new Number(1), - new Boolean(true), - new String('str'), - Object.create(null)]; -} - -var coercibleValues = [1, - true, - 'string']; - -var nonCoercibleValues = [undefined, - null]; - -var valuesWithoutNull = coercibleValues.concat(undefined); - -function TestSetPrototypeOf(object, proto) { - assertEq(Object.setPrototypeOf(object, proto), object); - assertEq(Object.getPrototypeOf(object), proto); -} - -// check if Object.setPrototypeOf works with coercible values -for(var value of coercibleValues) { - assertEq(Object.setPrototypeOf(value, {}), value); - - assertThrowsInstanceOf(() => Object.getPrototypeOf(value), - TypeError, "Coercible values should not have a prototype"); -} - -// check if Object.setPrototypeOf fails on non-coercible values -for (var value of nonCoercibleValues) { - assertThrowsInstanceOf(() => Object.setPrototypeOf(value, {}), - TypeError, "Object.setPrototypeOf shouldn't work on non-coercible values"); -} - -// check if Object.setPrototypeOf works when prototype is set to non-objects -var objects = getObjects(); -for (var object of objects) { - for (var proto of valuesWithoutNull) { - assertThrowsInstanceOf(() => Object.setPrototypeOf(object, proto), - TypeError, "Object.setPrototypeOf fails when the prototype is set to non-objects"); - } -} - -// check if Object.setPrototypeOf works when prototype is set to objects -var objects1 = getObjects(); -var objects2 = getObjects(); -for (var object1 of objects1) { - for (var object2 of objects2) { - TestSetPrototypeOf(object1, object2); - } -} - -// check if Object.setPrototypeOf works when prototype is set to null -objects = getObjects(); -for (var object of objects) { - TestSetPrototypeOf(object, null); -} - -// check if Object.setPrototypeOf fails when object is not extensible -var objects = getObjects(); -var proto = {}; -for (var object of objects) { - Object.preventExtensions(object); - assertThrowsInstanceOf(() => Object.setPrototypeOf(object, proto), - TypeError, "Object.setPrototypeOf should fail when the object is not extensible"); -} - -// check if Object.setPrototypeOf works with prototype lookup -var object = {}; -assertEq('x' in object, false); -assertEq('y' in object, false); - -var oldProto = { - x: 'old x', - y: 'old y' -}; -Object.setPrototypeOf(object, oldProto); -assertEq(object.x, 'old x'); -assertEq(object.y, 'old y'); - -var newProto = { - x: 'new x' -}; -Object.setPrototypeOf(object, newProto); -assertEq(object.x, 'new x'); -assertEq('y' in object, false); - -// check if Object.setPrototypeOf throws TypeError on fewer arguments -assertThrowsInstanceOf(() => Object.setPrototypeOf(), - TypeError, "Object.setPrototypeOf throws TypeError when called without any parameters"); -assertThrowsInstanceOf(() => Object.setPrototypeOf({}), - TypeError, "Object.setPrototypeOf throws TypeError when called with 1 parameter");