Bug 1088002 part 1. Change GetLocationProperty to a JSNative. r=bholley

This commit is contained in:
Boris Zbarsky 2014-10-29 15:06:31 -04:00
parent 68ef0d96f2
commit be93dcf92a

View File

@ -109,8 +109,13 @@ static JSPrincipals *gJSPrincipals = nullptr;
static nsAutoString *gWorkingDirectory = nullptr; static nsAutoString *gWorkingDirectory = nullptr;
static bool 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) #if !defined(XP_WIN) && !defined(XP_UNIX)
//XXX: your platform should really implement this //XXX: your platform should really implement this
return false; return false;
@ -171,13 +176,13 @@ GetLocationProperty(JSContext *cx, HandleObject obj, HandleId id, MutableHandleV
if (NS_SUCCEEDED(location->IsSymlink(&symlink)) && if (NS_SUCCEEDED(location->IsSymlink(&symlink)) &&
!symlink) !symlink)
location->Normalize(); location->Normalize();
rv = xpc->WrapNative(cx, obj, location, rv = xpc->WrapNative(cx, &args.thisv().toObject(), location,
NS_GET_IID(nsIFile), NS_GET_IID(nsIFile),
getter_AddRefs(locationHolder)); getter_AddRefs(locationHolder));
if (NS_SUCCEEDED(rv) && if (NS_SUCCEEDED(rv) &&
locationHolder->GetJSObject()) { 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)) if (GetCurrentWorkingDirectory(workingDirectory))
gWorkingDirectory = &workingDirectory; gWorkingDirectory = &workingDirectory;
JS_DefineProperty(cx, glob, "__LOCATION__", JS::UndefinedHandleValue, 0, JS_DefineProperty(cx, glob, "__LOCATION__", JS::UndefinedHandleValue,
GetLocationProperty, nullptr); 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 // We are almost certainly going to run script here, so we need an
// AutoEntryScript. This is Gecko-specific and not in any spec. // AutoEntryScript. This is Gecko-specific and not in any spec.