Bug 939696 - isProxy for export helpers. r=bholley
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Tue, 26 Nov 2013 14:54:17 +0100
changeset 157533 6728f7b4e467cb3a0968276f6679949f6d87e141
parent 157532 017167e2056a23c6d7660adaf556d57c65e58251
child 157534 ecf073f6394b871b4dc24d460c5266cd09956d9f
push id25716
push userkwierso@gmail.com
push dateWed, 27 Nov 2013 01:32:11 +0000
treeherdermozilla-central@d822990ba9ee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs939696
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 939696 - isProxy for export helpers. r=bholley
js/xpconnect/src/Sandbox.cpp
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -214,16 +214,37 @@ CreateXMLHttpRequest(JSContext *cx, unsi
 
     rv = nsContentUtils::WrapNative(cx, global, xhr, args.rval());
     if (NS_FAILED(rv))
         return false;
 
     return true;
 }
 
+static bool
+IsProxy(JSContext *cx, unsigned argc, jsval *vp)
+{
+    CallArgs args = CallArgsFromVp(argc, vp);
+    if (args.length() < 1) {
+        JS_ReportError(cx, "Function requires at least 1 argument");
+        return false;
+    }
+    if (!args[0].isObject()) {
+        args.rval().setBoolean(false);
+        return true;
+    }
+
+    RootedObject obj(cx, &args[0].toObject());
+    obj = js::CheckedUnwrap(obj);
+    NS_ENSURE_TRUE(obj, false);
+
+    args.rval().setBoolean(js::IsScriptedProxy(obj));
+    return true;
+}
+
 namespace xpc {
 
 bool
 ExportFunction(JSContext *cx, HandleValue vfunction, HandleValue vscope, HandleValue vname,
                MutableHandleValue rval)
 {
     if (!vscope.isObject() || !vfunction.isObject() || !vname.isString()) {
         JS_ReportError(cx, "Invalid argument");
@@ -1085,17 +1106,18 @@ xpc::CreateSandboxObject(JSContext *cx, 
             return NS_ERROR_XPC_UNEXPECTED;
 
         if (!JS_DefineFunctions(cx, sandbox, SandboxFunctions))
             return NS_ERROR_XPC_UNEXPECTED;
 
         if (options.wantExportHelpers &&
             (!JS_DefineFunction(cx, sandbox, "exportFunction", ExportFunction, 3, 0) ||
              !JS_DefineFunction(cx, sandbox, "evalInWindow", EvalInWindow, 2, 0) ||
-             !JS_DefineFunction(cx, sandbox, "createObjectIn", CreateObjectIn, 2, 0)))
+             !JS_DefineFunction(cx, sandbox, "createObjectIn", CreateObjectIn, 2, 0) ||
+             !JS_DefineFunction(cx, sandbox, "isProxy", IsProxy, 1, 0)))
             return NS_ERROR_XPC_UNEXPECTED;
 
         if (!options.globalProperties.Define(cx, sandbox))
             return NS_ERROR_XPC_UNEXPECTED;
     }
 
 
     // We have this crazy behavior where wantXrays=false also implies that the