mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1171053 - Remove JS_BindCallable. r=efaust
This commit is contained in:
parent
4d9139659d
commit
b56cf26ce7
@ -12,7 +12,6 @@ UNIFIED_SOURCES += [
|
||||
'testArgumentsObject.cpp',
|
||||
'testArrayBuffer.cpp',
|
||||
'testArrayBufferView.cpp',
|
||||
'testBindCallable.cpp',
|
||||
'testBug604087.cpp',
|
||||
'testCallNonGenericMethodOnProxy.cpp',
|
||||
'testChromeBuffer.cpp',
|
||||
|
@ -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)
|
@ -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)
|
||||
{
|
||||
|
@ -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<JSObject*> callable, JS::Handle<JSObject*> 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.
|
||||
|
@ -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<JSFunction>() && !target->as<JSFunction>().hasResolvedLength()) {
|
||||
uint16_t len;
|
||||
if (!target->as<JSFunction>().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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user