1333143 - Self-host Object.prototype.valueOf.

This commit is contained in:
Gaming4JC 2019-06-08 17:19:11 -04:00 committed by Roy Tam
commit 337cdbd0ce
7 changed files with 26 additions and 19 deletions

View file

@ -525,18 +525,6 @@ js::obj_toString(JSContext* cx, unsigned argc, Value* vp)
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
obj_setPrototypeOf(JSContext* cx, unsigned argc, Value* vp)
{
@ -1301,7 +1289,7 @@ static const JSFunctionSpec object_methods[] = {
#endif
JS_FN(js_toString_str, obj_toString, 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
JS_FN(js_watch_str, obj_watch, 2,0),
JS_FN(js_unwatch_str, obj_unwatch, 1,0),

View file

@ -25,9 +25,6 @@ obj_construct(JSContext* cx, unsigned argc, JS::Value* vp);
MOZ_MUST_USE bool
obj_propertyIsEnumerable(JSContext* cx, unsigned argc, Value* vp);
MOZ_MUST_USE bool
obj_valueOf(JSContext* cx, unsigned argc, JS::Value* vp);
PlainObject*
ObjectCreateImpl(JSContext* cx, HandleObject proto, NewObjectKind newKind = GenericObject,
HandleObjectGroup group = nullptr);

View file

@ -87,6 +87,12 @@ function Object_toLocaleString() {
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
function ObjectDefineSetter(name, setter) {
// Step 1.

View file

@ -8,7 +8,7 @@ function addDebug(g, id) {\
var debuggerGlobal = newGlobal();\
debuggerGlobal.debuggee = g;\
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; };');\
return debuggerGlobal;\
}\

View file

@ -31,7 +31,7 @@ cold_and_warm(Object.prototype.toString, { ToString: {} }, []);
var toS = { toString: function myToString() { return "string"; } };
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; } };
cold_and_warm(vOf.valueOf, { ToNumber: vOf }, [ "myValueOf" ]);

View file

@ -238,6 +238,7 @@
macro(other, other, "other") \
macro(outOfMemory, outOfMemory, "out of memory") \
macro(ownKeys, ownKeys, "ownKeys") \
macro(Object_valueOf, Object_valueOf, "Object_valueOf") \
macro(parseFloat, parseFloat, "parseFloat") \
macro(parseInt, parseInt, "parseInt") \
macro(pattern, pattern, "pattern") \

View file

@ -34,6 +34,7 @@
#include "frontend/Parser.h"
#include "gc/Policy.h"
#include "js/MemoryMetrics.h"
#include "vm/SelfHosting.h"
#include "vm/StringBuffer.h"
#include "vm/Time.h"
#include "vm/TypedArrayObject.h"
@ -7464,6 +7465,20 @@ GetDataProperty(JSContext* cx, HandleValue objVal, ImmutablePropertyNamePtr fiel
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
HasPureCoercion(JSContext* cx, HandleValue v)
{
@ -7480,7 +7495,7 @@ HasPureCoercion(JSContext* cx, HandleValue v)
// most apps have been built with newer Emscripten.
if (v.toObject().is<JSFunction>() &&
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))
{
return true;