Skip to content

Commit

Permalink
Bug 332648 - Part b: Move AutoValueRooter to jsapi.h; r=evilpie
Browse files Browse the repository at this point in the history
This patch also moves the MarkRuntime function into the JS namespace.
  • Loading branch information
Ms2ger committed Jan 11, 2012
1 parent 535b447 commit 69ca8de
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 89 deletions.
5 changes: 2 additions & 3 deletions content/base/src/nsFrameMessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

#include "ContentChild.h"
#include "ContentParent.h"
#include "jscntxt.h"
#include "nsFrameMessageManager.h"
#include "nsContentUtils.h"
#include "nsIXPConnect.h"
Expand Down Expand Up @@ -425,7 +424,7 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
}
}

js::AutoValueRooter objectsv(ctx);
JS::AutoValueRooter objectsv(ctx);
objectsv.set(OBJECT_TO_JSVAL(aObjectsArray));
if (!JS_WrapValue(ctx, objectsv.jsval_addr()))
return NS_ERROR_UNEXPECTED;
Expand Down Expand Up @@ -481,7 +480,7 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,

jsval rval = JSVAL_VOID;

js::AutoValueRooter argv(ctx);
JS::AutoValueRooter argv(ctx);
argv.set(OBJECT_TO_JSVAL(param));

{
Expand Down
12 changes: 7 additions & 5 deletions content/canvas/src/CustomQS_Canvas2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include "CheckedInt.h"
#include "nsMathUtils.h"

#include "jsapi.h"

typedef NS_STDCALL_FUNCPROTO(nsresult, CanvasStyleSetterType, nsIDOMCanvasRenderingContext2D,
SetStrokeStyle_multi, (const nsAString &, nsISupports *));
typedef NS_STDCALL_FUNCPROTO(nsresult, CanvasStyleGetterType, nsIDOMCanvasRenderingContext2D,
Expand All @@ -55,7 +57,7 @@ Canvas2D_SetStyleHelper(JSContext *cx, JSObject *obj, jsid id, jsval *vp,
XPC_QS_ASSERT_CONTEXT_OK(cx);
nsIDOMCanvasRenderingContext2D *self;
xpc_qsSelfRef selfref;
js::AutoValueRooter tvr(cx);
JS::AutoValueRooter tvr(cx);
if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
return JS_FALSE;

Expand Down Expand Up @@ -300,7 +302,7 @@ nsIDOMCanvasRenderingContext2D_GetImageData(JSContext *cx, uintN argc, jsval *vp

nsIDOMCanvasRenderingContext2D *self;
xpc_qsSelfRef selfref;
js::AutoValueRooter tvr(cx);
JS::AutoValueRooter tvr(cx);
if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
return JS_FALSE;

Expand Down Expand Up @@ -359,7 +361,7 @@ nsIDOMCanvasRenderingContext2D_PutImageData(JSContext *cx, uintN argc, jsval *vp

nsIDOMCanvasRenderingContext2D *self;
xpc_qsSelfRef selfref;
js::AutoValueRooter tvr(cx);
JS::AutoValueRooter tvr(cx);
if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
return JS_FALSE;

Expand Down Expand Up @@ -387,7 +389,7 @@ nsIDOMCanvasRenderingContext2D_PutImageData(JSContext *cx, uintN argc, jsval *vp
int32_t y = JS_DoubleToInt32(yd);

// Grab width, height, and the dense array from the dataObject.
js::AutoValueRooter tv(cx);
JS::AutoValueRooter tv(cx);

uint32_t w, h;
if (!GetImageDataDimensions(cx, dataObject, &w, &h))
Expand Down Expand Up @@ -430,7 +432,7 @@ nsIDOMCanvasRenderingContext2D_PutImageData(JSContext *cx, uintN argc, jsval *vp

JSObject *darray = JSVAL_TO_OBJECT(tv.jsval_value());

js::AutoValueRooter tsrc_tvr(cx);
JS::AutoValueRooter tsrc_tvr(cx);

JSObject *tsrc = NULL;
if (js::GetObjectClass(darray) == &js::TypedArray::fastClasses[js::TypedArray::TYPE_UINT8] ||
Expand Down
27 changes: 14 additions & 13 deletions content/canvas/src/CustomQS_WebGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* Intended to be #included in dom_quickstubs.cpp via qsconf!
*/

#include "jsapi.h"
#include "jstypedarray.h"

#define GET_INT32_ARG(var, index) \
Expand Down Expand Up @@ -91,7 +92,7 @@ nsIDOMWebGLRenderingContext_BufferData(JSContext *cx, uintN argc, jsval *vp)

nsIDOMWebGLRenderingContext *self;
xpc_qsSelfRef selfref;
js::AutoValueRooter tvr(cx);
JS::AutoValueRooter tvr(cx);
if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
return JS_FALSE;

Expand Down Expand Up @@ -164,7 +165,7 @@ nsIDOMWebGLRenderingContext_BufferSubData(JSContext *cx, uintN argc, jsval *vp)

nsIDOMWebGLRenderingContext *self;
xpc_qsSelfRef selfref;
js::AutoValueRooter tvr(cx);
JS::AutoValueRooter tvr(cx);
if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
return JS_FALSE;

Expand Down Expand Up @@ -238,7 +239,7 @@ nsIDOMWebGLRenderingContext_ReadPixels(JSContext *cx, uintN argc, jsval *vp)

nsIDOMWebGLRenderingContext *self;
xpc_qsSelfRef selfref;
js::AutoValueRooter tvr(cx);
JS::AutoValueRooter tvr(cx);
if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
return JS_FALSE;

Expand Down Expand Up @@ -298,7 +299,7 @@ nsIDOMWebGLRenderingContext_TexImage2D(JSContext *cx, uintN argc, jsval *vp)

nsIDOMWebGLRenderingContext *self;
xpc_qsSelfRef selfref;
js::AutoValueRooter tvr(cx);
JS::AutoValueRooter tvr(cx);
if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
return JS_FALSE;

Expand Down Expand Up @@ -419,7 +420,7 @@ nsIDOMWebGLRenderingContext_TexSubImage2D(JSContext *cx, uintN argc, jsval *vp)

nsIDOMWebGLRenderingContext *self;
xpc_qsSelfRef selfref;
js::AutoValueRooter tvr(cx);
JS::AutoValueRooter tvr(cx);
if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
return JS_FALSE;

Expand Down Expand Up @@ -530,7 +531,7 @@ helper_nsIDOMWebGLRenderingContext_Uniform_x_iv(JSContext *cx, uintN argc, jsval

nsIDOMWebGLRenderingContext *self;
xpc_qsSelfRef selfref;
js::AutoValueRooter tvr(cx);
JS::AutoValueRooter tvr(cx);
if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
return JS_FALSE;

Expand All @@ -554,7 +555,7 @@ helper_nsIDOMWebGLRenderingContext_Uniform_x_iv(JSContext *cx, uintN argc, jsval

JSObject *arg1 = JSVAL_TO_OBJECT(argv[1]);

js::AutoValueRooter obj_tvr(cx);
JS::AutoValueRooter obj_tvr(cx);

JSObject *wa = 0;

Expand Down Expand Up @@ -604,7 +605,7 @@ helper_nsIDOMWebGLRenderingContext_Uniform_x_fv(JSContext *cx, uintN argc, jsval

nsIDOMWebGLRenderingContext *self;
xpc_qsSelfRef selfref;
js::AutoValueRooter tvr(cx);
JS::AutoValueRooter tvr(cx);
if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
return JS_FALSE;

Expand All @@ -628,7 +629,7 @@ helper_nsIDOMWebGLRenderingContext_Uniform_x_fv(JSContext *cx, uintN argc, jsval

JSObject *arg1 = JSVAL_TO_OBJECT(argv[1]);

js::AutoValueRooter obj_tvr(cx);
JS::AutoValueRooter obj_tvr(cx);

JSObject *wa = 0;

Expand Down Expand Up @@ -676,7 +677,7 @@ helper_nsIDOMWebGLRenderingContext_UniformMatrix_x_fv(JSContext *cx, uintN argc,

nsIDOMWebGLRenderingContext *self;
xpc_qsSelfRef selfref;
js::AutoValueRooter tvr(cx);
JS::AutoValueRooter tvr(cx);
if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
return JS_FALSE;

Expand Down Expand Up @@ -704,7 +705,7 @@ helper_nsIDOMWebGLRenderingContext_UniformMatrix_x_fv(JSContext *cx, uintN argc,

JSObject *arg2 = JSVAL_TO_OBJECT(argv[2]);

js::AutoValueRooter obj_tvr(cx);
JS::AutoValueRooter obj_tvr(cx);

JSObject *wa = 0;

Expand Down Expand Up @@ -749,7 +750,7 @@ helper_nsIDOMWebGLRenderingContext_VertexAttrib_x_fv(JSContext *cx, uintN argc,

nsIDOMWebGLRenderingContext *self;
xpc_qsSelfRef selfref;
js::AutoValueRooter tvr(cx);
JS::AutoValueRooter tvr(cx);
if (!xpc_qsUnwrapThis(cx, obj, nsnull, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
return JS_FALSE;

Expand All @@ -769,7 +770,7 @@ helper_nsIDOMWebGLRenderingContext_VertexAttrib_x_fv(JSContext *cx, uintN argc,

JSObject *arg1 = JSVAL_TO_OBJECT(argv[1]);

js::AutoValueRooter obj_tvr(cx);
JS::AutoValueRooter obj_tvr(cx);

JSObject *wa = 0;

Expand Down
3 changes: 1 addition & 2 deletions content/html/content/src/nsHTMLAudioElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
#include "nsIScriptSecurityManager.h"
#include "nsIXPConnect.h"
#include "jsapi.h"
#include "jscntxt.h"
#include "jsfriendapi.h"
#include "jstypedarray.h"
#include "nsJSUtils.h"
Expand Down Expand Up @@ -197,7 +196,7 @@ nsHTMLAudioElement::MozWriteAudio(const jsval &aData, JSContext *aCx, PRUint32 *
}

JSObject *darray = JSVAL_TO_OBJECT(aData);
js::AutoValueRooter tsrc_tvr(aCx);
JS::AutoValueRooter tsrc_tvr(aCx);
JSObject *tsrc = NULL;

// Allow either Float32Array or plain JS Array
Expand Down
3 changes: 2 additions & 1 deletion dom/plugins/base/nsJSNPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include "base/basictypes.h"

#include "jsapi.h"
// FIXME(bug 332648): Give me a real API please!
#include "jscntxt.h"
#include "jsfriendapi.h"
Expand Down Expand Up @@ -869,7 +870,7 @@ nsJSObjWrapper::NP_SetProperty(NPObject *npobj, NPIdentifier id,
return false;

jsval v = NPVariantToJSVal(npp, cx, value);
js::AutoValueRooter tvr(cx, v);
JS::AutoValueRooter tvr(cx, v);

NS_ASSERTION(NPIdentifierIsInt(id) || NPIdentifierIsString(id),
"id must be either string or int!\n");
Expand Down
60 changes: 60 additions & 0 deletions js/src/jsapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,10 @@ class JS_PUBLIC_API(AutoCheckRequestDepth)

#endif

extern void
MarkRuntime(JSTracer *trc);


class JS_PUBLIC_API(AutoGCRooter) {
public:
AutoGCRooter(JSContext *cx, ptrdiff_t tag);
Expand Down Expand Up @@ -858,6 +862,62 @@ class JS_PUBLIC_API(AutoGCRooter) {
void operator=(AutoGCRooter &ida) MOZ_DELETE;
};

class AutoValueRooter : private AutoGCRooter
{
public:
explicit AutoValueRooter(JSContext *cx
JS_GUARD_OBJECT_NOTIFIER_PARAM)
: AutoGCRooter(cx, JSVAL), val(NullValue())
{
JS_GUARD_OBJECT_NOTIFIER_INIT;
}

AutoValueRooter(JSContext *cx, const Value &v
JS_GUARD_OBJECT_NOTIFIER_PARAM)
: AutoGCRooter(cx, JSVAL), val(v)
{
JS_GUARD_OBJECT_NOTIFIER_INIT;
}

/*
* If you are looking for Object* overloads, use AutoObjectRooter instead;
* rooting Object*s as a js::Value requires discerning whether or not it is
* a function object. Also, AutoObjectRooter is smaller.
*/

void set(Value v) {
JS_ASSERT(tag == JSVAL);
val = v;
}

const Value &value() const {
JS_ASSERT(tag == JSVAL);
return val;
}

Value *addr() {
JS_ASSERT(tag == JSVAL);
return &val;
}

const Value &jsval_value() const {
JS_ASSERT(tag == JSVAL);
return val;
}

Value *jsval_addr() {
JS_ASSERT(tag == JSVAL);
return &val;
}

friend void AutoGCRooter::trace(JSTracer *trc);
friend void MarkRuntime(JSTracer *trc);

private:
Value val;
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
};

} /* namespace JS */

/************************************************************************/
Expand Down
60 changes: 2 additions & 58 deletions js/src/jscntxt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1598,62 +1598,6 @@ typedef RootedVar<jsid> RootedVarId;
typedef RootedVar<Value> RootedVarValue;

/* FIXME(bug 332648): Move this into a public header. */
class AutoValueRooter : private AutoGCRooter
{
public:
explicit AutoValueRooter(JSContext *cx
JS_GUARD_OBJECT_NOTIFIER_PARAM)
: AutoGCRooter(cx, JSVAL), val(js::NullValue())
{
JS_GUARD_OBJECT_NOTIFIER_INIT;
}

AutoValueRooter(JSContext *cx, const Value &v
JS_GUARD_OBJECT_NOTIFIER_PARAM)
: AutoGCRooter(cx, JSVAL), val(v)
{
JS_GUARD_OBJECT_NOTIFIER_INIT;
}

/*
* If you are looking for Object* overloads, use AutoObjectRooter instead;
* rooting Object*s as a js::Value requires discerning whether or not it is
* a function object. Also, AutoObjectRooter is smaller.
*/

void set(Value v) {
JS_ASSERT(tag == JSVAL);
val = v;
}

const Value &value() const {
JS_ASSERT(tag == JSVAL);
return val;
}

Value *addr() {
JS_ASSERT(tag == JSVAL);
return &val;
}

const jsval &jsval_value() const {
JS_ASSERT(tag == JSVAL);
return val;
}

jsval *jsval_addr() {
JS_ASSERT(tag == JSVAL);
return &val;
}

friend void AutoGCRooter::trace(JSTracer *trc);
friend void MarkRuntime(JSTracer *trc);

private:
Value val;
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
};

class AutoObjectRooter : private AutoGCRooter {
public:
AutoObjectRooter(JSContext *cx, JSObject *obj = NULL
Expand Down Expand Up @@ -1758,7 +1702,7 @@ class AutoIdRooter : private AutoGCRooter
}

friend void AutoGCRooter::trace(JSTracer *trc);
friend void MarkRuntime(JSTracer *trc);
friend void JS::MarkRuntime(JSTracer *trc);

private:
jsid id_;
Expand Down Expand Up @@ -1848,7 +1792,7 @@ class AutoXMLRooter : private AutoGCRooter {
}

friend void AutoGCRooter::trace(JSTracer *trc);
friend void MarkRuntime(JSTracer *trc);
friend void JS::MarkRuntime(JSTracer *trc);

private:
JSXML * const xml;
Expand Down
Loading

0 comments on commit 69ca8de

Please sign in to comment.