diff options
Diffstat (limited to 'js/xpconnect')
-rw-r--r-- | js/xpconnect/loader/mozJSSubScriptLoader.cpp | 4 | ||||
-rw-r--r-- | js/xpconnect/src/ExportHelpers.cpp | 11 | ||||
-rw-r--r-- | js/xpconnect/src/XPCJSContext.cpp | 30 | ||||
-rw-r--r-- | js/xpconnect/src/XPCShellImpl.cpp | 23 | ||||
-rw-r--r-- | js/xpconnect/src/XPCVariant.cpp | 8 | ||||
-rw-r--r-- | js/xpconnect/src/XPCWrappedNative.cpp | 7 | ||||
-rw-r--r-- | js/xpconnect/tests/chrome/test_xrayToJS.xul | 18 | ||||
-rw-r--r-- | js/xpconnect/tests/unit/test_exportFunction.js | 3 | ||||
-rw-r--r-- | js/xpconnect/tests/unit/test_xray_regexp.js | 9 | ||||
-rw-r--r-- | js/xpconnect/tests/unit/xpcshell.ini | 1 | ||||
-rw-r--r-- | js/xpconnect/wrappers/XrayWrapper.cpp | 20 |
11 files changed, 45 insertions, 89 deletions
diff --git a/js/xpconnect/loader/mozJSSubScriptLoader.cpp b/js/xpconnect/loader/mozJSSubScriptLoader.cpp index 824e9ab9e..9c8908ea4 100644 --- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp +++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp @@ -130,7 +130,9 @@ PrepareScript(nsIURI* uri, MutableHandleFunction function) { JS::CompileOptions options(cx); - options.setFileAndLine(uriStr, 1) + // Use line 0 to make the function body starts from line 1 when + // |reuseGlobal == true|. + options.setFileAndLine(uriStr, reuseGlobal ? 0 : 1) .setVersion(JSVERSION_LATEST); if (!charset.IsVoid()) { char16_t* scriptBuf = nullptr; diff --git a/js/xpconnect/src/ExportHelpers.cpp b/js/xpconnect/src/ExportHelpers.cpp index 3dbf83e3b..e574e708c 100644 --- a/js/xpconnect/src/ExportHelpers.cpp +++ b/js/xpconnect/src/ExportHelpers.cpp @@ -329,11 +329,20 @@ NewFunctionForwarder(JSContext* cx, HandleId idArg, HandleObject callable, if (id == JSID_VOIDHANDLE) id = GetJSIDByIndex(cx, XPCJSContext::IDX_EMPTYSTRING); + // If our callable is a (possibly wrapped) function, we can give + // the exported thing the right number of args. + unsigned nargs = 0; + RootedObject unwrapped(cx, js::UncheckedUnwrap(callable)); + if (unwrapped) { + if (JSFunction* fun = JS_GetObjectFunction(unwrapped)) + nargs = JS_GetFunctionArity(fun); + } + // We have no way of knowing whether the underlying function wants to be a // constructor or not, so we just mark all forwarders as constructors, and // let the underlying function throw for construct calls if it wants. JSFunction* fun = js::NewFunctionByIdWithReserved(cx, FunctionForwarder, - 0, JSFUN_CONSTRUCTOR, id); + nargs, JSFUN_CONSTRUCTOR, id); if (!fun) return false; diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index defd1b785..8862bca32 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -59,14 +59,6 @@ #include "nsIXULRuntime.h" #include "nsJSPrincipals.h" -#ifdef MOZ_CRASHREPORTER -#include "nsExceptionHandler.h" -#endif - -#if defined(MOZ_JEMALLOC4) -#include "mozmemory.h" -#endif - #ifdef XP_WIN #include <windows.h> #endif @@ -151,18 +143,6 @@ public: mActive = false; } } else { -#if defined(MOZ_JEMALLOC4) - if (mPurge) { - /* Jemalloc purges dirty pages regularly during free() when the - * ratio of dirty pages compared to active pages is higher than - * 1 << lg_dirty_mult. A high ratio can have an impact on - * performance, so we use the default ratio of 8, but force a - * regular purge of all remaining dirty pages, after cycle - * collection. */ - Telemetry::AutoTimer<Telemetry::MEMORY_FREE_PURGED_PAGES_MS> timer; - jemalloc_free_dirty_pages(); - } -#endif mActive = false; } return NS_OK; @@ -709,11 +689,6 @@ XPCJSContext::GCSliceCallback(JSContext* cx, if (!self) return; -#ifdef MOZ_CRASHREPORTER - CrashReporter::SetGarbageCollecting(progress == JS::GC_CYCLE_BEGIN || - progress == JS::GC_SLICE_BEGIN); -#endif - if (self->mPrevGCSliceCallback) (*self->mPrevGCSliceCallback)(cx, progress, desc); } @@ -1473,6 +1448,8 @@ ReloadPrefsCallback(const char* pref, void* data) sExtraWarningsForSystemJS = Preferences::GetBool(JS_OPTIONS_DOT_STR "strict.debug"); #endif + bool arrayProtoValues = Preferences::GetBool(JS_OPTIONS_DOT_STR "array_prototype_values"); + JS::ContextOptionsRef(cx).setBaseline(useBaseline) .setIon(useIon) .setAsmJS(useAsmJS) @@ -1484,7 +1461,8 @@ ReloadPrefsCallback(const char* pref, void* data) .setThrowOnDebuggeeWouldRun(throwOnDebuggeeWouldRun) .setDumpStackOnDebuggeeWouldRun(dumpStackOnDebuggeeWouldRun) .setWerror(werror) - .setExtraWarnings(extraWarnings); + .setExtraWarnings(extraWarnings) + .setArrayProtoValues(arrayProtoValues); JS_SetParallelParsingEnabled(cx, parallelParsing); JS_SetOffthreadIonCompilationEnabled(cx, offthreadIonCompilation); diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index d9629bfed..45d00d390 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -59,11 +59,6 @@ #include <unistd.h> /* for isatty() */ #endif -#ifdef MOZ_CRASHREPORTER -#include "nsExceptionHandler.h" -#include "nsICrashReporter.h" -#endif - using namespace mozilla; using namespace JS; using mozilla::dom::AutoJSAPI; @@ -1372,18 +1367,6 @@ XRE_XPCShellMain(int argc, char** argv, char** envp, argv += 2; } -#ifdef MOZ_CRASHREPORTER - const char* val = getenv("MOZ_CRASHREPORTER"); - if (val && *val) { - rv = CrashReporter::SetExceptionHandler(greDir, true); - if (NS_FAILED(rv)) { - printf("CrashReporter::SetExceptionHandler failed!\n"); - return 1; - } - MOZ_ASSERT(CrashReporter::GetEnabled()); - } -#endif - { if (argc > 1 && !strcmp(argv[1], "--greomni")) { nsCOMPtr<nsIFile> greOmni; @@ -1603,12 +1586,6 @@ XRE_XPCShellMain(int argc, char** argv, char** envp, dirprovider.ClearPluginDir(); dirprovider.ClearAppFile(); -#ifdef MOZ_CRASHREPORTER - // Shut down the crashreporter service to prevent leaking some strings it holds. - if (CrashReporter::GetEnabled()) - CrashReporter::UnsetExceptionHandler(); -#endif - NS_LogTerm(); return result; diff --git a/js/xpconnect/src/XPCVariant.cpp b/js/xpconnect/src/XPCVariant.cpp index a3d2b88c5..4c1230172 100644 --- a/js/xpconnect/src/XPCVariant.cpp +++ b/js/xpconnect/src/XPCVariant.cpp @@ -55,7 +55,7 @@ XPCTraceableVariant::~XPCTraceableVariant() { Value val = GetJSValPreserveColor(); - MOZ_ASSERT(val.isGCThing(), "Must be traceable or unlinked"); + MOZ_ASSERT(val.isGCThing() || val.isNull(), "Must be traceable or unlinked"); mData.Cleanup(); @@ -65,7 +65,7 @@ XPCTraceableVariant::~XPCTraceableVariant() void XPCTraceableVariant::TraceJS(JSTracer* trc) { - MOZ_ASSERT(GetJSValPreserveColor().isMarkable()); + MOZ_ASSERT(GetJSValPreserveColor().isGCThing()); JS::TraceEdge(trc, &mJSVal, "XPCTraceableVariant::mJSVal"); } @@ -86,7 +86,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(XPCVariant) tmp->mData.Cleanup(); - if (val.isMarkable()) { + if (val.isGCThing()) { XPCTraceableVariant* v = static_cast<XPCTraceableVariant*>(tmp); v->RemoveFromRootSet(); } @@ -99,7 +99,7 @@ XPCVariant::newVariant(JSContext* cx, const Value& aJSVal) { RefPtr<XPCVariant> variant; - if (!aJSVal.isMarkable()) + if (!aJSVal.isGCThing()) variant = new XPCVariant(cx, aJSVal); else variant = new XPCTraceableVariant(cx, aJSVal); diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index acf92f3c3..a12e36baa 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -1785,9 +1785,12 @@ CallMethodHelper::ConvertIndependentParam(uint8_t i) // indirectly, regardless of in/out-ness. if (type_tag == nsXPTType::T_JSVAL) { // Root the value. - dp->val.j.setUndefined(); - if (!js::AddRawValueRoot(mCallContext, &dp->val.j, "XPCWrappedNative::CallMethod param")) + dp->val.j.asValueRef().setUndefined(); + if (!js::AddRawValueRoot(mCallContext, &dp->val.j.asValueRef(), + "XPCWrappedNative::CallMethod param")) + { return false; + } } // Flag cleanup for anything that isn't self-contained. diff --git a/js/xpconnect/tests/chrome/test_xrayToJS.xul b/js/xpconnect/tests/chrome/test_xrayToJS.xul index 2f4e70f47..ed67a34fe 100644 --- a/js/xpconnect/tests/chrome/test_xrayToJS.xul +++ b/js/xpconnect/tests/chrome/test_xrayToJS.xul @@ -198,9 +198,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681 "pop", "shift", "unshift", "splice", "concat", "slice", "lastIndexOf", "indexOf", "includes", "forEach", "map", "reduce", "reduceRight", "filter", "some", "every", "find", "findIndex", "copyWithin", "fill", Symbol.iterator, Symbol.unscopables, "entries", "keys", - "constructor"]; + "values", "constructor"]; if (isNightlyBuild) { - gPrototypeProperties['Array'].push("values"); + // ...nothing now } gConstructorProperties['Array'] = constructorProps(["join", "reverse", "sort", "push", "pop", "shift", @@ -220,11 +220,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681 // There is no TypedArray constructor, looks like. is(window.TypedArray, undefined, "If this ever changes, add to this test!"); for (var c of errorObjectClasses) { - gPrototypeProperties[c] = ["constructor", "name", - // We don't actually resolve these empty data properties - // onto the Xray prototypes, but we list them here to make - // the test happy. - "lineNumber", "columnNumber", "fileName", "message", "stack"]; + gPrototypeProperties[c] = ["constructor", "name", "message", "stack"]; gConstructorProperties[c] = constructorProps([]); } // toString and toSource only live on the parent proto (Error.prototype). @@ -239,8 +235,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681 gPrototypeProperties['RegExp'] = ["constructor", "toSource", "toString", "compile", "exec", "test", Symbol.match, Symbol.replace, Symbol.search, Symbol.split, - "flags", "global", "ignoreCase", "multiline", "source", "sticky", "unicode", - "lastIndex"]; + "flags", "global", "ignoreCase", "multiline", "source", "sticky", "unicode"]; gConstructorProperties['RegExp'] = constructorProps(["input", "lastMatch", "lastParen", "leftContext", "rightContext", "$1", "$2", "$3", "$4", @@ -791,8 +786,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681 // We only invoke testXray with Error, because that function isn't set up // to deal with dependent classes and fixing it up is more trouble than // it's worth. - testXray('Error', new iwin.Error('some error message'), new iwin.Error(), - ['fileName', 'lineNumber', 'columnNumber', 'message']); + testXray('Error', new iwin.Error('some error message'), new iwin.Error()); // Make sure that the dependent classes have their prototypes set up correctly. for (let c of errorObjectClasses.filter(x => x != "Error")) { @@ -806,7 +800,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681 e.wrappedJSObject[name] = goodReplacement; is(e[name], goodReplacement, name + " property ok after replacement: " + goodReplacement); e.wrappedJSObject[name] = faultyReplacement; - is(e[name], undefined, name + " property censored after suspicious replacement"); + is(e[name], name == 'message' ? "" : undefined, name + " property skipped after suspicious replacement"); } testProperty('message', x => x == 'some message', 'some other message', 42); testProperty('fileName', x => x == '', 'otherFilename.html', new iwin.Object()); diff --git a/js/xpconnect/tests/unit/test_exportFunction.js b/js/xpconnect/tests/unit/test_exportFunction.js index 830816342..9e1bf2082 100644 --- a/js/xpconnect/tests/unit/test_exportFunction.js +++ b/js/xpconnect/tests/unit/test_exportFunction.js @@ -10,12 +10,14 @@ function run_test() { epsb.do_check_true = do_check_true; epsb.do_check_eq = do_check_eq; subsb.do_check_true = do_check_true; + subsb.do_check_eq = do_check_eq; // Exporting should work if prinicipal of the source sandbox // subsumes the principal of the target sandbox. Cu.evalInSandbox("(" + function() { var wasCalled = false; this.funToExport = function(expectedThis, a, obj, native, mixed, callback) { + do_check_eq(arguments.callee.length, 6); do_check_eq(a, 42); do_check_eq(obj, subsb.tobecloned); do_check_eq(obj.cloned, "cloned"); @@ -53,6 +55,7 @@ function run_test() { invokedCallback = false; callback = function() { invokedCallback = true; }; imported(this, 42, tobecloned, native, mixed, callback); + do_check_eq(imported.length, 6); do_check_true(invokedCallback); }.toSource() + ")()", subsb); diff --git a/js/xpconnect/tests/unit/test_xray_regexp.js b/js/xpconnect/tests/unit/test_xray_regexp.js new file mode 100644 index 000000000..4baffd63e --- /dev/null +++ b/js/xpconnect/tests/unit/test_xray_regexp.js @@ -0,0 +1,9 @@ +const Cu = Components.utils; + +function run_test() { + var sandbox = Cu.Sandbox('http://www.example.com'); + var regexp = Cu.evalInSandbox("/test/i", sandbox); + equal(RegExp.prototype.toString.call(regexp), "/test/i"); + var prototype = Cu.evalInSandbox("RegExp.prototype", sandbox); + equal(typeof prototype.lastIndex, "undefined"); +} diff --git a/js/xpconnect/tests/unit/xpcshell.ini b/js/xpconnect/tests/unit/xpcshell.ini index 99d44b975..12648d3ec 100644 --- a/js/xpconnect/tests/unit/xpcshell.ini +++ b/js/xpconnect/tests/unit/xpcshell.ini @@ -133,5 +133,6 @@ head = head_watchdog.js [test_xrayed_iterator.js] [test_xray_SavedFrame.js] [test_xray_SavedFrame-02.js] +[test_xray_regexp.js] [test_resolve_dead_promise.js] [test_asyncLoadSubScriptError.js] diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index 5e537692d..48a9fdc68 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -636,18 +636,6 @@ JSXrayTraits::resolveOwnProperty(JSContext* cx, const Wrapper& jsWrapper, return true; } - // Handle the 'name' property for error prototypes. - if (IsErrorObjectKey(key) && id == GetJSIDByIndex(cx, XPCJSContext::IDX_NAME)) { - RootedId className(cx); - ProtoKeyToId(cx, key, &className); - FillPropertyDescriptor(desc, wrapper, 0, UndefinedValue()); - return JS_IdToValue(cx, className, desc.value()); - } - - // Handle the 'lastIndex' property for RegExp prototypes. - if (key == JSProto_RegExp && id == GetJSIDByIndex(cx, XPCJSContext::IDX_LASTINDEX)) - return getOwnPropertyFromWrapperIfSafe(cx, wrapper, id, desc); - // Grab the JSClass. We require all Xrayable classes to have a ClassSpec. const js::Class* clasp = js::GetObjectClass(target); MOZ_ASSERT(clasp->specDefined()); @@ -889,14 +877,6 @@ JSXrayTraits::enumerateNames(JSContext* cx, HandleObject wrapper, unsigned flags if (!props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_CONSTRUCTOR))) return false; - // For Error protoypes, add the 'name' property. - if (IsErrorObjectKey(key) && !props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_NAME))) - return false; - - // For RegExp protoypes, add the 'lastIndex' property. - if (key == JSProto_RegExp && !props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_LASTINDEX))) - return false; - // Grab the JSClass. We require all Xrayable classes to have a ClassSpec. const js::Class* clasp = js::GetObjectClass(target); MOZ_ASSERT(clasp->specDefined()); |