Skip to content

Commit

Permalink
Bug 959787 - Handlify JS_ExecuteScript, JS_EvaluateScript and other J…
Browse files Browse the repository at this point in the history
…S APIs r=sfink r=bz
  • Loading branch information
jonco3 committed Mar 17, 2014
1 parent 846b035 commit 46fe908
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 84 deletions.
3 changes: 2 additions & 1 deletion dom/base/nsJSUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ nsJSUtils::EvaluateString(JSContext* aCx,

JS::Rooted<JSObject*> rootedScope(aCx, aScopeObject);
if (aOffThreadToken) {
JSScript *script = JS::FinishOffThreadScript(aCx, JS_GetRuntime(aCx), *aOffThreadToken);
JS::Rooted<JSScript*>
script(aCx, JS::FinishOffThreadScript(aCx, JS_GetRuntime(aCx), *aOffThreadToken));
*aOffThreadToken = nullptr; // Mark the token as having been finished.
if (script) {
ok = JS_ExecuteScript(aCx, rootedScope, script, aRetValue);
Expand Down
5 changes: 2 additions & 3 deletions dom/xbl/nsXBLBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,9 +1185,8 @@ nsXBLBinding::LookupMemberInternal(JSContext* aCx, nsString& aName,
// Look for the property on this binding. If it's not there, try the next
// binding on the chain.
nsXBLProtoImpl* impl = mPrototypeBinding->GetImplementation();
if (impl && !impl->LookupMember(aCx, aName, aNameAsId, aDesc,
&classObject.toObject()))
{
JS::Rooted<JSObject*> object(aCx, &classObject.toObject());
if (impl && !impl->LookupMember(aCx, aName, aNameAsId, aDesc, object)) {
return false;
}
if (aDesc.object() || !mNextBinding) {
Expand Down
2 changes: 1 addition & 1 deletion dom/xbl/nsXBLProtoImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ bool
nsXBLProtoImpl::LookupMember(JSContext* aCx, nsString& aName,
JS::Handle<jsid> aNameAsId,
JS::MutableHandle<JSPropertyDescriptor> aDesc,
JSObject* aClassObject)
JS::Handle<JSObject*> aClassObject)
{
for (nsXBLProtoImplMember* m = mMembers; m; m = m->GetNext()) {
if (aName.Equals(m->GetName())) {
Expand Down
2 changes: 1 addition & 1 deletion dom/xbl/nsXBLProtoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class nsXBLProtoImpl MOZ_FINAL

bool LookupMember(JSContext* aCx, nsString& aName, JS::Handle<jsid> aNameAsId,
JS::MutableHandle<JSPropertyDescriptor> aDesc,
JSObject* aClassObject);
JS::Handle<JSObject*> aClassObject);

void SetMemberList(nsXBLProtoImplMember* aMemberList)
{
Expand Down
13 changes: 6 additions & 7 deletions ipc/testshell/XPCShellEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ Load(JSContext *cx,
JS::CompileOptions options(cx);
options.setUTF8(true)
.setFileAndLine(filename.ptr(), 1);
JS::RootedObject rootedObj(cx, obj);
JSScript *script = JS::Compile(cx, rootedObj, options, file);
JS::Rooted<JSScript*> script(cx, JS::Compile(cx, obj, options, file));
fclose(file);
if (!script)
return false;
Expand Down Expand Up @@ -298,7 +297,6 @@ XPCShellEnvironment::ProcessFile(JSContext *cx,
{
XPCShellEnvironment* env = this;

JSScript *script;
JS::Rooted<JS::Value> result(cx);
int lineno, startline;
bool ok, hitEOF;
Expand Down Expand Up @@ -333,7 +331,7 @@ XPCShellEnvironment::ProcessFile(JSContext *cx,
JS::CompileOptions options(cx);
options.setUTF8(true)
.setFileAndLine(filename, 1);
JSScript* script = JS::Compile(cx, obj, options, file);
JS::Rooted<JSScript*> script(cx, JS::Compile(cx, obj, options, file));
if (script)
(void)JS_ExecuteScript(cx, obj, script, result.address());

Expand Down Expand Up @@ -370,7 +368,8 @@ XPCShellEnvironment::ProcessFile(JSContext *cx,
JS_ClearPendingException(cx);
JS::CompileOptions options(cx);
options.setFileAndLine("typein", startline);
script = JS_CompileScript(cx, obj, buffer, strlen(buffer), options);
JS::Rooted<JSScript*> script(cx,
JS_CompileScript(cx, obj, buffer, strlen(buffer), options));
if (script) {
JSErrorReporter older;

Expand Down Expand Up @@ -578,8 +577,8 @@ XPCShellEnvironment::EvaluateString(const nsString& aString,

JS::CompileOptions options(cx);
options.setFileAndLine("typein", 0);
JSScript* script = JS_CompileUCScript(cx, global, aString.get(),
aString.Length(), options);
JS::Rooted<JSScript*> script(cx, JS_CompileUCScript(cx, global, aString.get(),
aString.Length(), options));
if (!script) {
return false;
}
Expand Down
6 changes: 4 additions & 2 deletions js/src/jit/AsmJSLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ LinkFail(JSContext *cx, const char *str)
}

static bool
GetDataProperty(JSContext *cx, const Value &objVal, HandlePropertyName field, MutableHandleValue v)
GetDataProperty(JSContext *cx, HandleValue objVal, HandlePropertyName field, MutableHandleValue v)
{
if (!objVal.isObject())
return LinkFail(cx, "accessing property of non-object");

Rooted<JSPropertyDescriptor> desc(cx);
if (!JS_GetPropertyDescriptorById(cx, &objVal.toObject(), NameToId(field), 0, &desc))
RootedObject obj(cx, &objVal.toObject());
RootedId id(cx, NameToId(field));
if (!JS_GetPropertyDescriptorById(cx, obj, id, 0, &desc))
return false;

if (!desc.object())
Expand Down
44 changes: 18 additions & 26 deletions js/src/jsapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3096,11 +3096,8 @@ JS_DefineUCProperty(JSContext *cx, JSObject *objArg, const jschar *name, size_t
}

JS_PUBLIC_API(bool)
JS_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg, jsval descriptorArg, bool *bp)
JS_DefineOwnProperty(JSContext *cx, HandleObject obj, HandleId id, HandleValue descriptor, bool *bp)
{
RootedObject obj(cx, objArg);
RootedId id(cx, idArg);
RootedValue descriptor(cx, descriptorArg);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj, id, descriptor);
Expand Down Expand Up @@ -3136,9 +3133,8 @@ JS_DefineObject(JSContext *cx, JSObject *objArg, const char *name, const JSClass
}

JS_PUBLIC_API(bool)
JS_DefineConstDoubles(JSContext *cx, JSObject *objArg, const JSConstDoubleSpec *cds)
JS_DefineConstDoubles(JSContext *cx, HandleObject obj, const JSConstDoubleSpec *cds)
{
RootedObject obj(cx, objArg);
bool ok;
unsigned attrs;

Expand All @@ -3159,9 +3155,8 @@ JS_DefineConstDoubles(JSContext *cx, JSObject *objArg, const JSConstDoubleSpec *
}

JS_PUBLIC_API(bool)
JS_DefineProperties(JSContext *cx, JSObject *objArg, const JSPropertySpec *ps)
JS_DefineProperties(JSContext *cx, HandleObject obj, const JSPropertySpec *ps)
{
RootedObject obj(cx, objArg);
bool ok;
for (ok = true; ps->name; ps++) {
if (ps->flags & JSPROP_NATIVE_ACCESSORS) {
Expand Down Expand Up @@ -3245,42 +3240,42 @@ GetPropertyDescriptorById(JSContext *cx, HandleObject obj, HandleId id, unsigned
}

JS_PUBLIC_API(bool)
JS_GetOwnPropertyDescriptorById(JSContext *cx, JSObject *objArg, jsid idArg, unsigned flags,
JS_GetOwnPropertyDescriptorById(JSContext *cx, HandleObject obj, HandleId id, unsigned flags,
MutableHandle<JSPropertyDescriptor> desc)
{
RootedObject obj(cx, objArg);
RootedId id(cx, idArg);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);

return GetPropertyDescriptorById(cx, obj, id, flags, true, desc);
}

JS_PUBLIC_API(bool)
JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, unsigned flags,
JS_GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, const char *name, unsigned flags,
MutableHandle<JSPropertyDescriptor> desc)
{
RootedObject obj(cx, objArg);
JSAtom *atom = Atomize(cx, name, strlen(name));
return atom && JS_GetOwnPropertyDescriptorById(cx, obj, AtomToId(atom), flags, desc);
if (!atom)
return false;
RootedId id(cx, AtomToId(atom));
return JS_GetOwnPropertyDescriptorById(cx, obj, id, flags, desc);
}

JS_PUBLIC_API(bool)
JS_GetPropertyDescriptorById(JSContext *cx, JSObject *objArg, jsid idArg, unsigned flags,
JS_GetPropertyDescriptorById(JSContext *cx, HandleObject obj, HandleId id, unsigned flags,
MutableHandle<JSPropertyDescriptor> desc)
{
RootedObject obj(cx, objArg);
RootedId id(cx, idArg);
return GetPropertyDescriptorById(cx, obj, id, flags, false, desc);
}

JS_PUBLIC_API(bool)
JS_GetPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, unsigned flags,
JS_GetPropertyDescriptor(JSContext *cx, HandleObject obj, const char *name, unsigned flags,
MutableHandle<JSPropertyDescriptor> desc)
{
RootedObject obj(cx, objArg);
JSAtom *atom = Atomize(cx, name, strlen(name));
return atom && JS_GetPropertyDescriptorById(cx, obj, AtomToId(atom), flags, desc);
if (!atom)
return false;
RootedId id(cx, AtomToId(atom));
return atom && JS_GetPropertyDescriptorById(cx, obj, id, flags, desc);
}

JS_PUBLIC_API(bool)
Expand Down Expand Up @@ -4712,9 +4707,8 @@ JS_DecompileFunctionBody(JSContext *cx, HandleFunction fun, unsigned indent)
}

MOZ_NEVER_INLINE JS_PUBLIC_API(bool)
JS_ExecuteScript(JSContext *cx, JSObject *objArg, JSScript *scriptArg, jsval *rval)
JS_ExecuteScript(JSContext *cx, HandleObject obj, HandleScript scriptArg, jsval *rval)
{
RootedObject obj(cx, objArg);
RootedScript script(cx, scriptArg);

JS_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
Expand Down Expand Up @@ -4745,10 +4739,9 @@ JS_ExecuteScript(JSContext *cx, JSObject *objArg, JSScript *scriptArg, jsval *rv
}

JS_PUBLIC_API(bool)
JS_ExecuteScriptVersion(JSContext *cx, JSObject *objArg, JSScript *script, jsval *rval,
JS_ExecuteScriptVersion(JSContext *cx, HandleObject obj, HandleScript script, jsval *rval,
JSVersion version)
{
RootedObject obj(cx, objArg);
return JS_ExecuteScript(cx, obj, script, rval);
}

Expand Down Expand Up @@ -4839,10 +4832,9 @@ JS_EvaluateUCScript(JSContext *cx, HandleObject obj, const jschar *chars, unsign
}

JS_PUBLIC_API(bool)
JS_EvaluateScript(JSContext *cx, JSObject *objArg, const char *bytes, unsigned nbytes,
JS_EvaluateScript(JSContext *cx, HandleObject obj, const char *bytes, unsigned nbytes,
const char *filename, unsigned lineno, jsval *rval)
{
RootedObject obj(cx, objArg);
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);

Expand Down
23 changes: 12 additions & 11 deletions js/src/jsapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2770,10 +2770,10 @@ JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, const JSClass *c
JSObject *proto, unsigned attrs);

extern JS_PUBLIC_API(bool)
JS_DefineConstDoubles(JSContext *cx, JSObject *obj, const JSConstDoubleSpec *cds);
JS_DefineConstDoubles(JSContext *cx, JS::HandleObject obj, const JSConstDoubleSpec *cds);

extern JS_PUBLIC_API(bool)
JS_DefineProperties(JSContext *cx, JSObject *obj, const JSPropertySpec *ps);
JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps);

extern JS_PUBLIC_API(bool)
JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value,
Expand All @@ -2784,7 +2784,8 @@ JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value,
JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs);

extern JS_PUBLIC_API(bool)
JS_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id, jsval descriptor, bool *bp);
JS_DefineOwnProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
JS::HandleValue descriptor, bool *bp);

extern JS_PUBLIC_API(bool)
JS_AlreadyHasOwnProperty(JSContext *cx, JS::HandleObject obj, const char *name,
Expand Down Expand Up @@ -2960,11 +2961,11 @@ class MutableHandleBase<JSPropertyDescriptor>
} /* namespace js */

extern JS_PUBLIC_API(bool)
JS_GetOwnPropertyDescriptorById(JSContext *cx, JSObject *objArg, jsid id, unsigned flags,
JS::MutableHandle<JSPropertyDescriptor> desc);
JS_GetOwnPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
unsigned flags, JS::MutableHandle<JSPropertyDescriptor> desc);

extern JS_PUBLIC_API(bool)
JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, unsigned flags,
JS_GetOwnPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, unsigned flags,
JS::MutableHandle<JSPropertyDescriptor> desc);

/*
Expand All @@ -2973,11 +2974,11 @@ JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, const char *name, u
* then this property was not found on the prototype chain.
*/
extern JS_PUBLIC_API(bool)
JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, unsigned flags,
JS_GetPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, unsigned flags,
JS::MutableHandle<JSPropertyDescriptor> desc);

extern JS_PUBLIC_API(bool)
JS_GetPropertyDescriptor(JSContext *cx, JSObject *obj, const char *name, unsigned flags,
JS_GetPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name, unsigned flags,
JS::MutableHandle<JSPropertyDescriptor> desc);

extern JS_PUBLIC_API(bool)
Expand Down Expand Up @@ -3747,14 +3748,14 @@ JS_DecompileFunctionBody(JSContext *cx, JS::Handle<JSFunction*> fun, unsigned in
* etc., entry points.
*/
extern JS_PUBLIC_API(bool)
JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval);
JS_ExecuteScript(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, jsval *rval);

extern JS_PUBLIC_API(bool)
JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval,
JS_ExecuteScriptVersion(JSContext *cx, JS::HandleObject obj, JS::HandleScript script, jsval *rval,
JSVersion version);

extern JS_PUBLIC_API(bool)
JS_EvaluateScript(JSContext *cx, JSObject *obj,
JS_EvaluateScript(JSContext *cx, JS::HandleObject obj,
const char *bytes, unsigned length,
const char *filename, unsigned lineno,
jsval *rval);
Expand Down
4 changes: 2 additions & 2 deletions js/src/shell/js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2887,8 +2887,8 @@ WorkerMain(void *arg)
options.setFileAndLine("<string>", 1)
.setCompileAndGo(true);

JSScript *script = JS::Compile(cx, global, options,
input->chars, input->length);
RootedScript script(cx, JS::Compile(cx, global, options,
input->chars, input->length));
if (!script)
break;
RootedValue result(cx);
Expand Down
7 changes: 3 additions & 4 deletions js/xpconnect/src/XPCShellImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ Load(JSContext *cx, unsigned argc, jsval *vp)
JS::CompileOptions options(cx);
options.setUTF8(true)
.setFileAndLine(filename.ptr(), 1);
JS::RootedObject rootedObj(cx, obj);
JSScript *script = JS::Compile(cx, rootedObj, options, file);
JS::Rooted<JSScript*> script(cx, JS::Compile(cx, obj, options, file));
fclose(file);
if (!script)
return false;
Expand Down Expand Up @@ -892,8 +891,8 @@ static void
ProcessFile(JSContext *cx, JS::Handle<JSObject*> obj, const char *filename, FILE *file,
bool forceTTY)
{
JSScript *script;
JS::Rooted<JS::Value> result(cx);
JS::RootedScript script(cx);
JS::RootedValue result(cx);
int lineno, startline;
bool ok, hitEOF;
char *bufp, buffer[4096];
Expand Down
17 changes: 8 additions & 9 deletions netwerk/base/src/ProxyAutoConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,23 +613,22 @@ ProxyAutoConfig::SetupJS()
if (!mJSRuntime)
return NS_ERROR_FAILURE;

JSAutoRequest ar(mJSRuntime->Context());
JSAutoCompartment ac(mJSRuntime->Context(), mJSRuntime->Global());
JSContext* cx = mJSRuntime->Context();
JSAutoRequest ar(cx);
JSAutoCompartment ac(cx, mJSRuntime->Global());

// check if this is a data: uri so that we don't spam the js console with
// huge meaningless strings. this is not on the main thread, so it can't
// use nsIRUI scheme methods
bool isDataURI = nsDependentCSubstring(mPACURI, 0, 5).LowerCaseEqualsASCII("data:", 5);

sRunning = this;
JS::Rooted<JSObject *> global(mJSRuntime->Context(), mJSRuntime->Global());
JS::CompileOptions options(mJSRuntime->Context());
JS::Rooted<JSObject*> global(cx, mJSRuntime->Global());
JS::CompileOptions options(cx);
options.setFileAndLine(mPACURI.get(), 1);
JSScript *script = JS_CompileScript(mJSRuntime->Context(), global,
mPACScript.get(), mPACScript.Length(),
options);
if (!script ||
!JS_ExecuteScript(mJSRuntime->Context(), mJSRuntime->Global(), script, nullptr)) {
JS::Rooted<JSScript*> script(cx, JS_CompileScript(cx, global, mPACScript.get(),
mPACScript.Length(), options));
if (!script || !JS_ExecuteScript(cx, global, script, nullptr)) {
nsString alertMessage(NS_LITERAL_STRING("PAC file failed to install from "));
if (isDataURI) {
alertMessage += NS_LITERAL_STRING("data: URI");
Expand Down
Loading

0 comments on commit 46fe908

Please sign in to comment.