Bug 1131805 part 2. Remove remaining js::GetObjectParent and JS_GetParent uses in SpiderMonkey. r=waldo
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 06 Mar 2015 16:33:31 -0500
changeset 232329 4139522bf81411bb298025a7e2d405dc89f638d9
parent 232328 badf6f5f22f34519205fe399ffaec4817474774b
child 232330 d052486d57c3aeb1efba50c5e8e60ce0a01ea71e
push id11642
push userphilringnalda@gmail.com
push dateSun, 08 Mar 2015 03:44:35 +0000
treeherderfx-team@88b540f6db2a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs1131805
milestone39.0a1
Bug 1131805 part 2. Remove remaining js::GetObjectParent and JS_GetParent uses in SpiderMonkey. r=waldo
js/src/jsapi-tests/selfTest.cpp
js/src/jsapi-tests/testTypedArrays.cpp
js/src/jsapi.cpp
js/src/jsapi.h
js/src/jsfriendapi.h
js/src/shell/js.cpp
js/src/tests/js1_5/extensions/regress-164697.js
js/src/tests/js1_7/extensions/regress-355583.js
js/src/tests/js1_8/extensions/for-in.js
--- a/js/src/jsapi-tests/selfTest.cpp
+++ b/js/src/jsapi-tests/selfTest.cpp
@@ -13,15 +13,8 @@ BEGIN_TEST(selfTest_NaNsAreSame)
     EVAL("0/0", &v1);  // NaN
     CHECK_SAME(v1, v1);
 
     EVAL("Math.sin('no')", &v2);  // also NaN
     CHECK_SAME(v1, v2);
     return true;
 }
 END_TEST(selfTest_NaNsAreSame)
-
-BEGIN_TEST(selfTest_globalHasNoParent)
-{
-    CHECK(JS_GetParent(global) == nullptr);
-    return true;
-}
-END_TEST(selfTest_globalHasNoParent)
--- a/js/src/jsapi-tests/testTypedArrays.cpp
+++ b/js/src/jsapi-tests/testTypedArrays.cpp
@@ -28,18 +28,16 @@ BEGIN_TEST(testTypedArrays)
 
     size_t nbytes = sizeof(double) * 8;
     RootedObject buffer(cx, JS_NewArrayBuffer(cx, nbytes));
     CHECK(JS_IsArrayBufferObject(buffer));
 
     RootedObject proto(cx);
     JS_GetPrototype(cx, buffer, &proto);
     CHECK(!JS_IsArrayBufferObject(proto));
-    RootedObject dummy(cx, JS_GetParent(proto));
-    CHECK(!JS_IsArrayBufferObject(dummy));
 
     {
         JS::AutoCheckCannotGC nogc;
         CHECK_EQUAL(JS_GetArrayBufferByteLength(buffer), nbytes);
         memset(JS_GetArrayBufferData(buffer, nogc), 1, nbytes);
     }
 
     ok = ok &&
@@ -67,18 +65,16 @@ TestPlainTypedArray(JSContext *cx)
         CHECK(!notArray);
     }
 
     RootedObject array(cx, Create(cx, 7));
     CHECK(JS_IsTypedArrayObject(array));
     RootedObject proto(cx);
     JS_GetPrototype(cx, array, &proto);
     CHECK(!JS_IsTypedArrayObject(proto));
-    RootedObject dummy(cx, JS_GetParent(proto));
-    CHECK(!JS_IsTypedArrayObject(dummy));
 
     CHECK_EQUAL(JS_GetTypedArrayLength(array), 7u);
     CHECK_EQUAL(JS_GetTypedArrayByteOffset(array), 0u);
     CHECK_EQUAL(JS_GetTypedArrayByteLength(array), sizeof(Element) * 7);
 
     {
         JS::AutoCheckCannotGC nogc;
         Element *data;
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -1713,23 +1713,16 @@ JS_IsExtensible(JSContext *cx, HandleObj
 
 JS_PUBLIC_API(bool)
 JS_PreventExtensions(JSContext *cx, JS::HandleObject obj, bool *succeeded)
 {
     return PreventExtensions(cx, obj, succeeded);
 }
 
 JS_PUBLIC_API(JSObject *)
-JS_GetParent(JSObject *obj)
-{
-    MOZ_ASSERT(!obj->is<ScopeObject>());
-    return obj->getParent();
-}
-
-JS_PUBLIC_API(JSObject *)
 JS_GetConstructor(JSContext *cx, HandleObject proto)
 {
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, proto);
 
     RootedValue cval(cx);
     if (!GetProperty(cx, proto, proto, cx->names().constructor, &cval))
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -2238,19 +2238,16 @@ JS_GetInstancePrivate(JSContext *cx, JS:
 
 extern JS_PUBLIC_API(bool)
 JS_GetPrototype(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject protop);
 
 extern JS_PUBLIC_API(bool)
 JS_SetPrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto);
 
 extern JS_PUBLIC_API(JSObject *)
-JS_GetParent(JSObject *obj);
-
-extern JS_PUBLIC_API(JSObject *)
 JS_GetConstructor(JSContext *cx, JS::Handle<JSObject*> proto);
 
 namespace JS {
 
 enum ZoneSpecifier {
     FreshZone = 0,
     SystemZone = 1
 };
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -682,24 +682,16 @@ JS_FRIEND_API(bool)
 IsScopeObject(JSObject *obj);
 
 JS_FRIEND_API(bool)
 IsCallObject(JSObject *obj);
 
 JS_FRIEND_API(bool)
 CanAccessObjectShape(JSObject *obj);
 
-inline JSObject *
-GetObjectParent(JSObject *obj)
-{
-    MOZ_ASSERT(!IsScopeObject(obj));
-    MOZ_ASSERT(CanAccessObjectShape(obj));
-    return reinterpret_cast<shadow::Object*>(obj)->shape->base->parent;
-}
-
 static MOZ_ALWAYS_INLINE JSCompartment *
 GetObjectCompartment(JSObject *obj)
 {
     return reinterpret_cast<shadow::Object*>(obj)->group->compartment;
 }
 
 JS_FRIEND_API(JSObject *)
 GetGlobalForObjectCrossCompartment(JSObject *obj);
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2579,17 +2579,17 @@ Clone(JSContext *cx, unsigned argc, jsva
             return false;
         }
     }
 
     if (args.length() > 1) {
         if (!JS_ValueToObject(cx, args[1], &parent))
             return false;
     } else {
-        parent = JS_GetParent(&args.callee());
+        parent = js::GetGlobalForObjectCrossCompartment(&args.callee());
     }
 
     // Should it worry us that we might be getting with wrappers
     // around with wrappers here?
     JS::AutoObjectVector scopeChain(cx);
     if (!parent->is<GlobalObject>() && !scopeChain.append(parent))
         return false;
     JSObject *clone = JS::CloneFunctionObject(cx, funobj, scopeChain);
@@ -3233,44 +3233,16 @@ Elapsed(JSContext *cx, unsigned argc, js
         args.rval().setDouble(d);
         return true;
     }
     JS_ReportError(cx, "Wrong number of arguments");
     return false;
 }
 
 static bool
-Parent(JSContext *cx, unsigned argc, jsval *vp)
-{
-    CallArgs args = CallArgsFromVp(argc, vp);
-    if (args.length() != 1) {
-        JS_ReportError(cx, "Wrong number of arguments");
-        return false;
-    }
-
-    Value v = args[0];
-    if (v.isPrimitive()) {
-        JS_ReportError(cx, "Only objects have parents!");
-        return false;
-    }
-
-    Rooted<JSObject*> parent(cx, JS_GetParent(&v.toObject()));
-
-    /* Outerize if necessary. */
-    if (parent) {
-        parent = GetOuterObject(cx, parent);
-        if (!parent)
-            return false;
-    }
-
-    args.rval().setObjectOrNull(parent);
-    return true;
-}
-
-static bool
 Compile(JSContext *cx, unsigned argc, jsval *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     if (args.length() < 1) {
         JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED,
                              "compile", "0", "s");
         return false;
     }
@@ -4927,20 +4899,16 @@ static const JSFunctionSpecWithHelp fuzz
 "clone(fun[, scope])",
 "  Clone function object."),
 
     JS_FN_HELP("getSelfHostedValue", GetSelfHostedValue, 1, 0,
 "getSelfHostedValue()",
 "  Get a self-hosted value by its name. Note that these values don't get \n"
 "  cached, so repeatedly getting the same value creates multiple distinct clones."),
 
-    JS_FN_HELP("parent", Parent, 1, 0,
-"parent(obj)",
-"  Returns the parent of obj."),
-
     JS_FN_HELP("line2pc", LineToPC, 0, 0,
 "line2pc([fun,] line)",
 "  Map line number to PC."),
 
     JS_FN_HELP("pc2line", PCToLine, 0, 0,
 "pc2line(fun[, pc])",
 "  Map PC to line number."),
 
deleted file mode 100644
--- a/js/src/tests/js1_5/extensions/regress-164697.js
+++ /dev/null
@@ -1,80 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-//-----------------------------------------------------------------------------
-var BUGNUMBER = 164697;
-var summary = '(parent(instance) == parent(constructor))';
-var actual = '';
-var expect = '';
-
-printBugNumber(BUGNUMBER);
-printStatus (summary);
-
-expect = 'true';
-
-runtest('{}', 'Object');
-runtest('new Object()', 'Object');
-
-// see https://bugzilla.mozilla.org/show_bug.cgi?id=321669
-// for why this test is not contained in a function.
-actual = (function (){}).__proto__ == Function.prototype;
-reportCompare('true', actual+'',
-              '(function (){}).__proto__ == Function.prototype');
-
-runtest('new Function(";")', 'Function');
-
-runtest('[]', 'Array');
-runtest('new Array()', 'Array');
-
-runtest('new String()', 'String');
-
-runtest('new Boolean()', 'Boolean');
-
-runtest('new Number("1")', 'Number');
-
-runtest('new Date()', 'Date');
-
-runtest('/x/', 'RegExp');
-runtest('new RegExp("x")', 'RegExp');
-
-runtest('new Error()', 'Error');
-
-function runtest(myinstance, myconstructor)
-{
-  var expr;
-  var actual;
-
-  if (typeof parent === "function")
-  {
-    try
-    {
-      expr =
-        'parent(' + myinstance + ') == ' +
-        'parent(' + myconstructor + ')';
-      printStatus(expr);
-      actual = eval(expr).toString();
-    }
-    catch(ex)
-    {
-      actual = ex + '';
-    }
-
-    reportCompare(expect, actual, expr);
-  }
-
-  try
-  {
-    expr =  '(' + myinstance + ').__proto__ == ' +
-      myconstructor + '.prototype';
-    printStatus(expr);
-    actual = eval(expr).toString();
-  }
-  catch(ex)
-  {
-    actual = ex + '';
-  }
-
-  reportCompare(expect, actual, expr);
-}
deleted file mode 100644
--- a/js/src/tests/js1_7/extensions/regress-355583.js
+++ /dev/null
@@ -1,39 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-//-----------------------------------------------------------------------------
-var BUGNUMBER = 355583;
-var summary = 'block object access to arbitrary stack slots';
-var actual = '';
-var expect = '';
-
-
-//-----------------------------------------------------------------------------
-test();
-//-----------------------------------------------------------------------------
-
-function test()
-{
-  enterFunc ('test');
-  printBugNumber(BUGNUMBER);
-  printStatus (summary);
-
-  expect = 'No Crash';
-  actual = 'No Crash';
-  try
-  {
-    (function() {
-      let b = parent(function(){});
-      print(b[1] = throwError);
-    })();
-  }
-  catch(ex)
-  {
-
-  }
-  reportCompare(expect, actual, summary);
-
-  exitFunc ('test');
-}
deleted file mode 100644
--- a/js/src/tests/js1_8/extensions/for-in.js
+++ /dev/null
@@ -1,55 +0,0 @@
-// |reftest| skip
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/licenses/publicdomain/
- * Contributor: Jason Orendorff
- */
-
-//-----------------------------------------------------------------------------
-
-var summary = "Contention among threads enumerating properties";
-// Adapted from mozilla/js/src/xpconnect/tests/js/old/threads.js
-
-printStatus (summary);
-
-var LOOP_COUNT = 1000;
-var THREAD_COUNT = 10;
-
-var foo;
-var bar;
-
-function makeWorkerFn(id) {
-  return function() {
-    foo = id + 1;
-    bar[id] = {p: 0};
-    var n, m;
-    for (n in bar) {
-      for (m in bar[n]) {}
-    }
-    for (n in parent({})) {}
-  };
-}
-
-function range(n) {
-  for (let i = 0; i < n; i++)
-    yield i;
-}
-
-var expect;
-var actual;
-
-expect = actual = 'No crash';
-if (typeof scatter == 'undefined') {
-  print('Test skipped. scatter not defined.');
-} else if (typeof parent === "undefined") {
-  print('Test skipped, no parent() function.');
-} else {
-  for (let i = 0; i < LOOP_COUNT; i++) {
-    foo = 0;
-    bar = new Array(THREAD_COUNT);
-    scatter([makeWorkerFn(j) for (j in range(THREAD_COUNT))]);
-  }
-}
-
-reportCompare(expect, actual, summary);