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

@ -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;