JSObject * js_InitBooleanClass(JSContext *cx, HandleObject obj) { JS_ASSERT(obj->isNative()); Rooted<GlobalObject*> global(cx, &obj->asGlobal()); RootedObject booleanProto (cx, global->createBlankPrototype(cx, &BooleanClass)); if (!booleanProto) return NULL; booleanProto->setFixedSlot(BooleanObject::PRIMITIVE_VALUE_SLOT, BooleanValue(false)); RootedFunction ctor(cx, global->createConstructor(cx, Boolean, cx->names().Boolean, 1)); if (!ctor) return NULL; if (!LinkConstructorAndPrototype(cx, ctor, booleanProto)) return NULL; if (!DefinePropertiesAndBrand(cx, booleanProto, NULL, boolean_methods)) return NULL; Handle<PropertyName*> valueOfName = cx->names().valueOf; RootedFunction valueOf(cx, js_NewFunction(cx, NullPtr(), bool_valueOf, 0, JSFunction::NATIVE_FUN, global, valueOfName)); if (!valueOf) return NULL; RootedValue value(cx, ObjectValue(*valueOf)); if (!JSObject::defineProperty(cx, booleanProto, valueOfName, value, JS_PropertyStub, JS_StrictPropertyStub, 0)) { return NULL; } global->setBooleanValueOf(valueOf); if (!DefineConstructorAndPrototype(cx, global, JSProto_Boolean, ctor, booleanProto)) return NULL; return booleanProto; }
JSObject * js_InitBooleanClass(JSContext *cx, JSObject *obj) { JS_ASSERT(obj->isNative()); Rooted<GlobalObject*> global(cx, &obj->asGlobal()); RootedObject booleanProto (cx, global->createBlankPrototype(cx, &BooleanClass)); if (!booleanProto) return NULL; booleanProto->setFixedSlot(BooleanObject::PRIMITIVE_VALUE_SLOT, BooleanValue(false)); RootedFunction ctor(cx, global->createConstructor(cx, Boolean, CLASS_NAME(cx, Boolean), 1)); if (!ctor) return NULL; if (!LinkConstructorAndPrototype(cx, ctor, booleanProto)) return NULL; if (!DefinePropertiesAndBrand(cx, booleanProto, NULL, boolean_methods)) return NULL; Rooted<PropertyName*> valueOfName(cx, cx->runtime->atomState.valueOfAtom); Rooted<JSFunction*> valueOf(cx, js_NewFunction(cx, NULL, bool_valueOf, 0, 0, global, valueOfName)); if (!valueOf) return NULL; if (!booleanProto->defineProperty(cx, valueOfName, ObjectValue(*valueOf), JS_PropertyStub, JS_StrictPropertyStub, 0)) { return NULL; } global->setBooleanValueOf(valueOf); if (!DefineConstructorAndPrototype(cx, global, JSProto_Boolean, ctor, booleanProto)) return NULL; return booleanProto; }