Bug 1111248. r=Waldo

This commit is contained in:
Tom Schuster 2015-01-24 13:37:46 -05:00
parent 3dcde61c32
commit 88673d3751
4 changed files with 8 additions and 54 deletions

View File

@ -105,6 +105,7 @@ static const JSFunctionSpec boolean_methods[] = {
JS_FN(js_toSource_str, bool_toSource, 0, 0),
#endif
JS_FN(js_toString_str, bool_toString, 0, 0),
JS_FN(js_valueOf_str, bool_valueOf, 0, 0),
JS_FS_END
};
@ -148,17 +149,6 @@ js_InitBooleanClass(JSContext *cx, HandleObject obj)
if (!DefinePropertiesAndFunctions(cx, booleanProto, nullptr, boolean_methods))
return nullptr;
Handle<PropertyName*> valueOfName = cx->names().valueOf;
RootedFunction
valueOf(cx, NewFunction(cx, NullPtr(), bool_valueOf, 0, JSFunction::NATIVE_FUN,
global, valueOfName));
if (!valueOf)
return nullptr;
RootedValue value(cx, ObjectValue(*valueOf));
if (!DefineProperty(cx, booleanProto, valueOfName, value, nullptr, nullptr, 0))
return nullptr;
if (!GlobalObject::initBuiltinConstructor(cx, global, JSProto_Boolean, ctor, booleanProto))
return nullptr;
@ -180,15 +170,3 @@ js::ToBooleanSlow(HandleValue v)
MOZ_ASSERT(v.isObject());
return !EmulatesUndefined(&v.toObject());
}
/*
* This slow path is only ever taken for proxies wrapping Boolean objects
* The only caller of the fast path, JSON's PreprocessValue, ensures that.
*/
bool
js::BooleanGetPrimitiveValueSlow(HandleObject wrappedBool)
{
JSObject *obj = wrappedBool->as<ProxyObject>().target();
MOZ_ASSERT(obj);
return obj->as<BooleanObject>().unbox();
}

View File

@ -19,11 +19,4 @@ js_InitBooleanClass(JSContext *cx, js::HandleObject obj);
extern JSString *
js_BooleanToString(js::ExclusiveContext *cx, bool b);
namespace js {
inline bool
BooleanGetPrimitiveValue(HandleObject obj);
} /* namespace js */
#endif /* jsbool_h */

View File

@ -14,18 +14,6 @@
namespace js {
bool
BooleanGetPrimitiveValueSlow(HandleObject);
inline bool
BooleanGetPrimitiveValue(HandleObject obj)
{
if (obj->is<BooleanObject>())
return obj->as<BooleanObject>().unbox();
return BooleanGetPrimitiveValueSlow(obj);
}
inline bool
EmulatesUndefined(JSObject *obj)
{

View File

@ -263,14 +263,15 @@ PreprocessValue(JSContext *cx, HandleObject holder, KeyType key, MutableHandleVa
double d;
if (!ToNumber(cx, vp, &d))
return false;
vp.set(NumberValue(d));
vp.setNumber(d);
} else if (ObjectClassIs(obj, ESClass_String, cx)) {
JSString *str = ToStringSlow<CanGC>(cx, vp);
if (!str)
return false;
vp.set(StringValue(str));
vp.setString(str);
} else if (ObjectClassIs(obj, ESClass_Boolean, cx)) {
vp.setBoolean(BooleanGetPrimitiveValue(obj));
if (!Unbox(cx, obj, vp))
return false;
}
}
@ -892,16 +893,10 @@ js_InitJSONClass(JSContext *cx, HandleObject obj)
{
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
/*
* JSON requires that Boolean.prototype.valueOf be created and stashed in a
* reserved slot on the global object; see js::BooleanGetPrimitiveValueSlow
* called from PreprocessValue above.
*/
if (!GlobalObject::getOrCreateBooleanPrototype(cx, global))
RootedObject proto(cx, global->getOrCreateObjectPrototype(cx));
if (!proto)
return nullptr;
RootedObject proto(cx, obj->as<GlobalObject>().getOrCreateObjectPrototype(cx));
RootedObject JSON(cx, NewObjectWithClassProto(cx, &JSONClass, proto, global, SingletonObject));
RootedObject JSON(cx, NewObjectWithGivenProto(cx, &JSONClass, proto, global, SingletonObject));
if (!JSON)
return nullptr;