From be93dcf92a2f55d1701a50e938d25c60eb432a25 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 29 Oct 2014 15:06:31 -0400 Subject: [PATCH] Bug 1088002 part 1. Change GetLocationProperty to a JSNative. r=bholley --- js/xpconnect/src/XPCShellImpl.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index f653aa163e1..0ff378f930f 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -109,8 +109,13 @@ static JSPrincipals *gJSPrincipals = nullptr; static nsAutoString *gWorkingDirectory = nullptr; static bool -GetLocationProperty(JSContext *cx, HandleObject obj, HandleId id, MutableHandleValue vp) +GetLocationProperty(JSContext *cx, unsigned argc, Value *vp) { + CallArgs args = CallArgsFromVp(argc, vp); + if (!args.thisv().isObject()) { + JS_ReportError(cx, "Unexpected this value for GetLocationProperty"); + return false; + } #if !defined(XP_WIN) && !defined(XP_UNIX) //XXX: your platform should really implement this return false; @@ -171,13 +176,13 @@ GetLocationProperty(JSContext *cx, HandleObject obj, HandleId id, MutableHandleV if (NS_SUCCEEDED(location->IsSymlink(&symlink)) && !symlink) location->Normalize(); - rv = xpc->WrapNative(cx, obj, location, + rv = xpc->WrapNative(cx, &args.thisv().toObject(), location, NS_GET_IID(nsIFile), getter_AddRefs(locationHolder)); if (NS_SUCCEEDED(rv) && locationHolder->GetJSObject()) { - vp.set(OBJECT_TO_JSVAL(locationHolder->GetJSObject())); + args.rval().setObject(*locationHolder->GetJSObject()); } } } @@ -1497,8 +1502,10 @@ XRE_XPCShellMain(int argc, char **argv, char **envp) if (GetCurrentWorkingDirectory(workingDirectory)) gWorkingDirectory = &workingDirectory; - JS_DefineProperty(cx, glob, "__LOCATION__", JS::UndefinedHandleValue, 0, - GetLocationProperty, nullptr); + JS_DefineProperty(cx, glob, "__LOCATION__", JS::UndefinedHandleValue, + JSPROP_NATIVE_ACCESSORS | JSPROP_SHARED, + JS_CAST_NATIVE_TO(GetLocationProperty, JSPropertyOp), + nullptr); // We are almost certainly going to run script here, so we need an // AutoEntryScript. This is Gecko-specific and not in any spec.