From b56cf26ce7a7cff3682870b45046fb489c024da0 Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Thu, 2 Jul 2015 22:46:19 +0200 Subject: [PATCH] Bug 1171053 - Remove JS_BindCallable. r=efaust --- js/src/jsapi-tests/moz.build | 1 - js/src/jsapi-tests/testBindCallable.cpp | 32 -------------------- js/src/jsapi.cpp | 7 ----- js/src/jsapi.h | 8 ----- js/src/jsfun.cpp | 39 +++++++++---------------- js/src/jsfun.h | 4 --- 6 files changed, 14 insertions(+), 77 deletions(-) delete mode 100644 js/src/jsapi-tests/testBindCallable.cpp diff --git a/js/src/jsapi-tests/moz.build b/js/src/jsapi-tests/moz.build index 709b66054ed..b56126ac566 100644 --- a/js/src/jsapi-tests/moz.build +++ b/js/src/jsapi-tests/moz.build @@ -12,7 +12,6 @@ UNIFIED_SOURCES += [ 'testArgumentsObject.cpp', 'testArrayBuffer.cpp', 'testArrayBufferView.cpp', - 'testBindCallable.cpp', 'testBug604087.cpp', 'testCallNonGenericMethodOnProxy.cpp', 'testChromeBuffer.cpp', diff --git a/js/src/jsapi-tests/testBindCallable.cpp b/js/src/jsapi-tests/testBindCallable.cpp deleted file mode 100644 index 8b25e163fd7..00000000000 --- a/js/src/jsapi-tests/testBindCallable.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* 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/. */ - -#include "jsapi-tests/tests.h" - -BEGIN_TEST(test_BindCallable) -{ - JS::RootedValue v(cx); - EVAL("({ somename : 1717 })", &v); - CHECK(v.isObject()); - - JS::RootedValue func(cx); - EVAL("(function() { return this.somename; })", &func); - CHECK(func.isObject()); - - JS::RootedObject funcObj(cx, func.toObjectOrNull()); - JS::RootedObject vObj(cx, v.toObjectOrNull()); - JSObject* newCallable = JS_BindCallable(cx, funcObj, vObj); - CHECK(newCallable); - - JS::RootedValue retval(cx); - JS::RootedValue fun(cx, JS::ObjectValue(*newCallable)); - bool called = JS_CallFunctionValue(cx, nullptr, fun, JS::HandleValueArray::empty(), &retval); - CHECK(called); - - CHECK(retval.isInt32()); - - CHECK(retval.toInt32() == 1717); - return true; -} -END_TEST(test_BindCallable) diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 5153dffc574..ca5242b961b 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -3496,13 +3496,6 @@ JS_IsConstructor(JSFunction* fun) return fun->isConstructor(); } -JS_PUBLIC_API(JSObject*) -JS_BindCallable(JSContext* cx, HandleObject target, HandleObject newThis) -{ - RootedValue thisArg(cx, ObjectValue(*newThis)); - return fun_bind(cx, target, thisArg, nullptr, 0); -} - static bool GenericNativeMethodDispatcher(JSContext* cx, unsigned argc, Value* vp) { diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 3ea5c9c9af4..2ba4b8c0078 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -3280,14 +3280,6 @@ JS_IsNativeFunction(JSObject* funobj, JSNative call); extern JS_PUBLIC_API(bool) JS_IsConstructor(JSFunction* fun); -/* - * Bind the given callable to use the given object as "this". - * - * If |callable| is not callable, will throw and return nullptr. - */ -extern JS_PUBLIC_API(JSObject*) -JS_BindCallable(JSContext* cx, JS::Handle callable, JS::Handle newThis); - // This enum is used to select if properties with JSPROP_DEFINE_LATE flag // should be defined on the object. // Normal JSAPI consumers probably always want DefineAllProperties here. diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index fd2e8c8dd4b..0ad8602db1e 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -1586,42 +1586,29 @@ js::fun_bind(JSContext* cx, unsigned argc, Value* vp) argslen = args.length() - 1; } - // Steps 4-14. RootedValue thisArg(cx, args.length() >= 1 ? args[0] : UndefinedValue()); RootedObject target(cx, &thisv.toObject()); - JSObject* boundFunction = fun_bind(cx, target, thisArg, boundArgs, argslen); - if (!boundFunction) - return false; - // Step 15. - args.rval().setObject(*boundFunction); - return true; -} - -JSObject* -js::fun_bind(JSContext* cx, HandleObject target, HandleValue thisArg, - Value* boundArgs, unsigned argslen) -{ double length = 0.0; // Try to avoid invoking the resolve hook. if (target->is() && !target->as().hasResolvedLength()) { uint16_t len; if (!target->as().getLength(cx, &len)) - return nullptr; + return false; length = Max(0.0, double(len) - argslen); } else { // Steps 5-6. RootedId id(cx, NameToId(cx->names().length)); bool hasLength; if (!HasOwnProperty(cx, target, id, &hasLength)) - return nullptr; + return false; // Step 7-8. if (hasLength) { // a-b. RootedValue targetLen(cx); if (!GetProperty(cx, target, target, id, &targetLen)) - return nullptr; + return false; // d. if (targetLen.isNumber()) length = Max(0.0, JS::ToInteger(targetLen.toNumber()) - argslen); @@ -1636,7 +1623,7 @@ js::fun_bind(JSContext* cx, HandleObject target, HandleValue thisArg, // Steps 11-12. RootedValue targetName(cx); if (!GetProperty(cx, target, target, cx->names().name, &targetName)) - return nullptr; + return false; // Step 13. if (targetName.isString()) @@ -1647,23 +1634,23 @@ js::fun_bind(JSContext* cx, HandleObject target, HandleValue thisArg, StringBuffer sb(cx); // Disabled for B2G failures. // if (!sb.append("bound ") || !sb.append(name)) - // return nullptr; + // return false; if (!sb.append(name)) - return nullptr; + return false; RootedAtom nameAtom(cx, sb.finishAtom()); if (!nameAtom) - return nullptr; + return false; - // Step 4. + // Step 4. RootedFunction fun(cx, target->isConstructor() ? NewNativeConstructor(cx, CallOrConstructBoundFunction, length, nameAtom) : NewNativeFunction(cx, CallOrConstructBoundFunction, length, nameAtom)); if (!fun) - return nullptr; + return false; if (!fun->initBoundFunction(cx, target, thisArg, boundArgs, argslen)) - return nullptr; + return false; // Steps 9-10. Set length again, because NewNativeFunction/NewNativeConstructor // sometimes truncates. @@ -1672,11 +1659,13 @@ js::fun_bind(JSContext* cx, HandleObject target, HandleValue thisArg, if (!DefineProperty(cx, fun, cx->names().length, lengthVal, nullptr, nullptr, JSPROP_READONLY)) { - return nullptr; + return false; } } - return fun; + // Step 15. + args.rval().setObject(*fun); + return true; } /* diff --git a/js/src/jsfun.h b/js/src/jsfun.h index acc2c6f9b7c..a0b635e821f 100644 --- a/js/src/jsfun.h +++ b/js/src/jsfun.h @@ -734,10 +734,6 @@ fun_apply(JSContext* cx, unsigned argc, Value* vp); extern bool fun_call(JSContext* cx, unsigned argc, Value* vp); -extern JSObject* -fun_bind(JSContext* cx, HandleObject target, HandleValue thisArg, - Value* boundArgs, unsigned argslen); - } /* namespace js */ #ifdef DEBUG