зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1333143 - Self-host Object.prototype.valueOf. r=till
This commit is contained in:
Родитель
d1aa9f8545
Коммит
005e29fb24
|
@ -419,18 +419,6 @@ js::obj_toString(JSContext* cx, unsigned argc, Value* vp)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
js::obj_valueOf(JSContext* cx, unsigned argc, Value* vp)
|
|
||||||
{
|
|
||||||
CallArgs args = CallArgsFromVp(argc, vp);
|
|
||||||
RootedObject obj(cx, ToObject(cx, args.thisv()));
|
|
||||||
if (!obj)
|
|
||||||
return false;
|
|
||||||
args.rval().setObject(*obj);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
obj_setPrototypeOf(JSContext* cx, unsigned argc, Value* vp)
|
obj_setPrototypeOf(JSContext* cx, unsigned argc, Value* vp)
|
||||||
{
|
{
|
||||||
|
@ -1195,7 +1183,7 @@ static const JSFunctionSpec object_methods[] = {
|
||||||
#endif
|
#endif
|
||||||
JS_FN(js_toString_str, obj_toString, 0,0),
|
JS_FN(js_toString_str, obj_toString, 0,0),
|
||||||
JS_SELF_HOSTED_FN(js_toLocaleString_str, "Object_toLocaleString", 0, 0),
|
JS_SELF_HOSTED_FN(js_toLocaleString_str, "Object_toLocaleString", 0, 0),
|
||||||
JS_FN(js_valueOf_str, obj_valueOf, 0,0),
|
JS_SELF_HOSTED_FN(js_valueOf_str, "Object_valueOf", 0,0),
|
||||||
#if JS_HAS_OBJ_WATCHPOINT
|
#if JS_HAS_OBJ_WATCHPOINT
|
||||||
JS_FN(js_watch_str, obj_watch, 2,0),
|
JS_FN(js_watch_str, obj_watch, 2,0),
|
||||||
JS_FN(js_unwatch_str, obj_unwatch, 1,0),
|
JS_FN(js_unwatch_str, obj_unwatch, 1,0),
|
||||||
|
|
|
@ -25,9 +25,6 @@ obj_construct(JSContext* cx, unsigned argc, JS::Value* vp);
|
||||||
MOZ_MUST_USE bool
|
MOZ_MUST_USE bool
|
||||||
obj_propertyIsEnumerable(JSContext* cx, unsigned argc, Value* vp);
|
obj_propertyIsEnumerable(JSContext* cx, unsigned argc, Value* vp);
|
||||||
|
|
||||||
MOZ_MUST_USE bool
|
|
||||||
obj_valueOf(JSContext* cx, unsigned argc, JS::Value* vp);
|
|
||||||
|
|
||||||
PlainObject*
|
PlainObject*
|
||||||
ObjectCreateImpl(JSContext* cx, HandleObject proto, NewObjectKind newKind = GenericObject,
|
ObjectCreateImpl(JSContext* cx, HandleObject proto, NewObjectKind newKind = GenericObject,
|
||||||
HandleObjectGroup group = nullptr);
|
HandleObjectGroup group = nullptr);
|
||||||
|
|
|
@ -87,6 +87,12 @@ function Object_toLocaleString() {
|
||||||
return callContentFunction(O.toString, O);
|
return callContentFunction(O.toString, O);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ES 2017 draft bb96899bb0d9ef9be08164a26efae2ee5f25e875 19.1.3.7
|
||||||
|
function Object_valueOf() {
|
||||||
|
// Step 1.
|
||||||
|
return ToObject(this);
|
||||||
|
}
|
||||||
|
|
||||||
// ES7 draft (2016 March 8) B.2.2.3
|
// ES7 draft (2016 March 8) B.2.2.3
|
||||||
function ObjectDefineSetter(name, setter) {
|
function ObjectDefineSetter(name, setter) {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
|
|
|
@ -8,7 +8,7 @@ function addDebug(g, id) {\
|
||||||
var debuggerGlobal = newGlobal();\
|
var debuggerGlobal = newGlobal();\
|
||||||
debuggerGlobal.debuggee = g;\
|
debuggerGlobal.debuggee = g;\
|
||||||
debuggerGlobal.id = id;\
|
debuggerGlobal.id = id;\
|
||||||
debuggerGlobal.print = function (s) { (g) += s; };\
|
debuggerGlobal.print = function (s) { print(s); };\
|
||||||
debuggerGlobal.eval('var dbg = new Debugger(debuggee);dbg.onDebuggerStatement = function () { print(id); debugger; };');\
|
debuggerGlobal.eval('var dbg = new Debugger(debuggee);dbg.onDebuggerStatement = function () { print(id); debugger; };');\
|
||||||
return debuggerGlobal;\
|
return debuggerGlobal;\
|
||||||
}\
|
}\
|
||||||
|
|
|
@ -31,7 +31,7 @@ cold_and_warm(Object.prototype.toString, { ToString: {} }, []);
|
||||||
var toS = { toString: function myToString() { return "string"; } };
|
var toS = { toString: function myToString() { return "string"; } };
|
||||||
cold_and_warm(toS.toString, { ToString: toS }, [ "myToString" ]);
|
cold_and_warm(toS.toString, { ToString: toS }, [ "myToString" ]);
|
||||||
|
|
||||||
cold_and_warm(undefined, { ToNumber: {} }, []);
|
cold_and_warm(undefined, { ToNumber: 5 }, []);
|
||||||
|
|
||||||
var vOf = { valueOf: function myValueOf() { return 42; } };
|
var vOf = { valueOf: function myValueOf() { return 42; } };
|
||||||
cold_and_warm(vOf.valueOf, { ToNumber: vOf }, [ "myValueOf" ]);
|
cold_and_warm(vOf.valueOf, { ToNumber: vOf }, [ "myValueOf" ]);
|
||||||
|
|
|
@ -243,6 +243,7 @@
|
||||||
macro(other, other, "other") \
|
macro(other, other, "other") \
|
||||||
macro(outOfMemory, outOfMemory, "out of memory") \
|
macro(outOfMemory, outOfMemory, "out of memory") \
|
||||||
macro(ownKeys, ownKeys, "ownKeys") \
|
macro(ownKeys, ownKeys, "ownKeys") \
|
||||||
|
macro(Object_valueOf, Object_valueOf, "Object_valueOf") \
|
||||||
macro(parseFloat, parseFloat, "parseFloat") \
|
macro(parseFloat, parseFloat, "parseFloat") \
|
||||||
macro(parseInt, parseInt, "parseInt") \
|
macro(parseInt, parseInt, "parseInt") \
|
||||||
macro(pattern, pattern, "pattern") \
|
macro(pattern, pattern, "pattern") \
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "frontend/Parser.h"
|
#include "frontend/Parser.h"
|
||||||
#include "gc/Policy.h"
|
#include "gc/Policy.h"
|
||||||
#include "js/MemoryMetrics.h"
|
#include "js/MemoryMetrics.h"
|
||||||
|
#include "vm/SelfHosting.h"
|
||||||
#include "vm/StringBuffer.h"
|
#include "vm/StringBuffer.h"
|
||||||
#include "vm/Time.h"
|
#include "vm/Time.h"
|
||||||
#include "vm/TypedArrayObject.h"
|
#include "vm/TypedArrayObject.h"
|
||||||
|
@ -7449,6 +7450,20 @@ GetDataProperty(JSContext* cx, HandleValue objVal, ImmutablePropertyNamePtr fiel
|
||||||
return GetDataProperty(cx, objVal, fieldHandle, v);
|
return GetDataProperty(cx, objVal, fieldHandle, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
HasObjectValueOfMethodPure(JSObject* obj, JSContext* cx)
|
||||||
|
{
|
||||||
|
Value v;
|
||||||
|
if (!GetPropertyPure(cx, obj, NameToId(cx->names().valueOf), &v))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
JSFunction* fun;
|
||||||
|
if (!IsFunctionObject(v, &fun))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return IsSelfHostedFunctionWithName(fun, cx->names().Object_valueOf);
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
HasPureCoercion(JSContext* cx, HandleValue v)
|
HasPureCoercion(JSContext* cx, HandleValue v)
|
||||||
{
|
{
|
||||||
|
@ -7465,7 +7480,7 @@ HasPureCoercion(JSContext* cx, HandleValue v)
|
||||||
// most apps have been built with newer Emscripten.
|
// most apps have been built with newer Emscripten.
|
||||||
if (v.toObject().is<JSFunction>() &&
|
if (v.toObject().is<JSFunction>() &&
|
||||||
HasNoToPrimitiveMethodPure(&v.toObject(), cx) &&
|
HasNoToPrimitiveMethodPure(&v.toObject(), cx) &&
|
||||||
HasNativeMethodPure(&v.toObject(), cx->names().valueOf, obj_valueOf, cx) &&
|
HasObjectValueOfMethodPure(&v.toObject(), cx) &&
|
||||||
HasNativeMethodPure(&v.toObject(), cx->names().toString, fun_toString, cx))
|
HasNativeMethodPure(&v.toObject(), cx->names().toString, fun_toString, cx))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче