Bug 695756 - Implement js::BooleanObject. r=nnethercote.
authorTerrence Cole <terrence@mozilla.com>
Thu, 20 Oct 2011 22:47:30 -0700
changeset 79069 986f31890872449ffbaa9043cb00f25f18236ab3
parent 79068 17ef2ebb8ef98c90d3df71025cd896c000fd17bf
child 79070 d031d09fe889fb38e75a3f1ba996049cad4f37a9
push id247
push usertim.taubert@gmx.de
push dateSat, 22 Oct 2011 19:08:15 +0000
treeherderfx-team@72bb20c484a2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnnethercote
bugs695756
milestone10.0a1
Bug 695756 - Implement js::BooleanObject. r=nnethercote.
js/src/jsbool.cpp
js/src/jsobj.cpp
js/src/jsobj.h
--- a/js/src/jsbool.cpp
+++ b/js/src/jsbool.cpp
@@ -49,16 +49,17 @@
 #include "jscntxt.h"
 #include "jsinfer.h"
 #include "jsversion.h"
 #include "jslock.h"
 #include "jsnum.h"
 #include "jsobj.h"
 #include "jsstr.h"
 
+#include "vm/BooleanObject-inl.h"
 #include "vm/GlobalObject.h"
 
 #include "jsinferinlines.h"
 #include "jsobjinlines.h"
 #include "jsstrinlines.h"
 
 using namespace js;
 using namespace js::types;
@@ -129,27 +130,25 @@ static JSFunctionSpec boolean_methods[] 
     JS_FN(js_toString_str,  bool_toString,  0, 0),
     JS_FN(js_valueOf_str,   bool_valueOf,   0, 0),
     JS_FS_END
 };
 
 static JSBool
 Boolean(JSContext *cx, uintN argc, Value *vp)
 {
-    Value *argv = vp + 2;
-    bool b = argc != 0 ? js_ValueToBoolean(argv[0]) : false;
+    CallArgs args = CallArgsFromVp(argc, vp);
+
+    bool b = args.length() != 0 ? js_ValueToBoolean(args[0]) : false;
 
     if (IsConstructing(vp)) {
-        JSObject *obj = NewBuiltinClassInstance(cx, &BooleanClass);
-        if (!obj)
-            return false;
-        obj->setPrimitiveThis(BooleanValue(b));
-        vp->setObject(*obj);
+        JSObject *obj = BooleanObject::create(cx, b);
+        args.rval().setObject(*obj);
     } else {
-        vp->setBoolean(b);
+        args.rval().setBoolean(b);
     }
     return true;
 }
 
 JSObject *
 js_InitBooleanClass(JSContext *cx, JSObject *obj)
 {
     JS_ASSERT(obj->isNative());
@@ -200,24 +199,24 @@ BooleanGetPrimitiveValueSlow(JSContext *
     JS_ASSERT(obj.isProxy());
 
     /*
      * To respect the proxy abstraction, we can't simply unwrap and call
      * getPrimitiveThis on the wrapped object. All we know is that obj says
      * its [[Class]] is "Boolean". Boolean.prototype.valueOf is specified to
      * return the [[PrimitiveValue]] internal property, so call that instead.
      */
-    InvokeArgsGuard args;
-    if (!cx->stack.pushInvokeArgs(cx, 0, &args))
+    InvokeArgsGuard ag;
+    if (!cx->stack.pushInvokeArgs(cx, 0, &ag))
         return false;
-    args.calleev().setUndefined();
-    args.thisv().setObject(obj);
-    if (!GetProxyHandler(&obj)->nativeCall(cx, &obj, &BooleanClass, bool_valueOf, args))
+    ag.calleev().setUndefined();
+    ag.thisv().setObject(obj);
+    if (!GetProxyHandler(&obj)->nativeCall(cx, &obj, &BooleanClass, bool_valueOf, ag))
         return false;
-    *vp = args.rval();
+    *vp = ag.rval();
     return true;
 }
 
 }  /* namespace js */
 
 JSBool
 js_ValueToBoolean(const Value &v)
 {
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -86,16 +86,17 @@
 #include "frontend/Parser.h"
 
 #include "jsarrayinlines.h"
 #include "jsinterpinlines.h"
 #include "jsscopeinlines.h"
 #include "jsscriptinlines.h"
 #include "jsobjinlines.h"
 
+#include "vm/BooleanObject-inl.h"
 #include "vm/NumberObject-inl.h"
 #include "vm/StringObject-inl.h"
 
 #if JS_HAS_GENERATORS
 #include "jsiter.h"
 #endif
 
 #if JS_HAS_XML_SUPPORT
@@ -6778,22 +6779,17 @@ JSObject *
 PrimitiveToObject(JSContext *cx, const Value &v)
 {
     if (v.isString())
         return StringObject::create(cx, v.toString());
     if (v.isNumber())
         return NumberObject::create(cx, v.toNumber());
 
     JS_ASSERT(v.isBoolean());
-    JSObject *obj = NewBuiltinClassInstance(cx, &BooleanClass);
-    if (!obj)
-        return NULL;
-
-    obj->setPrimitiveThis(v);
-    return obj;
+    return BooleanObject::create(cx, v.toBoolean());
 }
 
 JSBool
 js_PrimitiveToObject(JSContext *cx, Value *vp)
 {
     JSObject *obj = PrimitiveToObject(cx, *vp);
     if (!obj)
         return false;
--- a/js/src/jsobj.h
+++ b/js/src/jsobj.h
@@ -343,16 +343,17 @@ extern Class SlowArrayClass;
 extern Class StopIterationClass;
 extern Class StringClass;
 extern Class StrictArgumentsObjectClass;
 extern Class WeakMapClass;
 extern Class WithClass;
 extern Class XMLFilterClass;
 
 class ArgumentsObject;
+class BooleanObject;
 class GlobalObject;
 class NormalArgumentsObject;
 class NumberObject;
 class StrictArgumentsObject;
 class StringObject;
 class RegExpObject;
 
 }  /* namespace js */
@@ -1019,16 +1020,17 @@ struct JSObject : js::gc::Cell {
     inline void setPrimitiveThis(const js::Value &pthis);
 
     static size_t getPrimitiveThisOffset() {
         /* All primitive objects have their value in a fixed slot. */
         return getFixedSlotOffset(JSSLOT_PRIMITIVE_THIS);
     }
 
   public:
+    inline js::BooleanObject *asBoolean();
     inline js::NumberObject *asNumber();
     inline js::StringObject *asString();
     inline js::RegExpObject *asRegExp();
 
     /*
      * Array-specific getters and setters (for both dense and slow arrays).
      */