diff --git a/js/src/builtin/Eval.cpp b/js/src/builtin/Eval.cpp index 49e7e2cd771a..bdf61f3bf27e 100644 --- a/js/src/builtin/Eval.cpp +++ b/js/src/builtin/Eval.cpp @@ -330,12 +330,7 @@ static bool EvalKernel(JSContext* cx, HandleValue v, EvalType evalType, } SourceText srcBuf; - - const char16_t* chars = linearChars.twoByteRange().begin().get(); - SourceOwnership ownership = linearChars.maybeGiveOwnershipToCaller() - ? SourceOwnership::TakeOwnership - : SourceOwnership::Borrowed; - if (!srcBuf.init(cx, chars, linearStr->length(), ownership)) { + if (!srcBuf.initMaybeBorrowed(cx, linearChars)) { return false; } diff --git a/js/src/builtin/ShadowRealm.cpp b/js/src/builtin/ShadowRealm.cpp index 23656bd298e5..adc7f3c2459f 100644 --- a/js/src/builtin/ShadowRealm.cpp +++ b/js/src/builtin/ShadowRealm.cpp @@ -222,12 +222,7 @@ static bool PerformShadowRealmEval(JSContext* cx, Handle sourceText, return false; } SourceText srcBuf; - - const char16_t* chars = linearChars.twoByteRange().begin().get(); - SourceOwnership ownership = linearChars.maybeGiveOwnershipToCaller() - ? SourceOwnership::TakeOwnership - : SourceOwnership::Borrowed; - if (!srcBuf.init(cx, chars, linearChars.length(), ownership)) { + if (!srcBuf.initMaybeBorrowed(cx, linearChars)) { return false; } diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index a5b77943feda..f44090dc6170 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -6131,15 +6131,6 @@ static bool EvalReturningScope(JSContext* cx, unsigned argc, Value* vp) { } } - AutoStableStringChars strChars(cx); - if (!strChars.initTwoByte(cx, str)) { - return false; - } - - mozilla::Range chars = strChars.twoByteRange(); - size_t srclen = chars.length(); - const char16_t* src = chars.begin().get(); - JS::AutoFilename filename; unsigned lineno; @@ -6150,8 +6141,12 @@ static bool EvalReturningScope(JSContext* cx, unsigned argc, Value* vp) { options.setNoScriptRval(true); options.setNonSyntacticScope(true); + AutoStableStringChars linearChars(cx); + if (!linearChars.initTwoByte(cx, str)) { + return false; + } JS::SourceText srcBuf; - if (!srcBuf.init(cx, src, srclen, SourceOwnership::Borrowed)) { + if (!srcBuf.initMaybeBorrowed(cx, linearChars)) { return false; } @@ -6362,8 +6357,7 @@ static bool CompileToStencil(JSContext* cx, uint32_t argc, Value* vp) { return false; } JS::SourceText srcBuf; - if (!srcBuf.init(cx, linearChars.twoByteChars(), src->length(), - JS::SourceOwnership::Borrowed)) { + if (!srcBuf.initMaybeBorrowed(cx, linearChars)) { return false; } @@ -6508,8 +6502,7 @@ static bool CompileToStencilXDR(JSContext* cx, uint32_t argc, Value* vp) { return false; } JS::SourceText srcBuf; - if (!srcBuf.init(cx, linearChars.twoByteChars(), src->length(), - JS::SourceOwnership::Borrowed)) { + if (!srcBuf.initMaybeBorrowed(cx, linearChars)) { return false; } @@ -7694,20 +7687,13 @@ JSScript* js::TestingFunctionArgumentToScript( JSContext* cx, HandleValue v, JSFunction** funp /* = nullptr */) { if (v.isString()) { // To convert a string to a script, compile it. Parse it as an ES6 Program. - Rooted linearStr( - cx, JS::StringToLinearString(cx, v.toString())); - if (!linearStr) { - return nullptr; - } - size_t len = JS::GetLinearStringLength(linearStr); + Rooted str(cx, v.toString()); AutoStableStringChars linearChars(cx); - if (!linearChars.initTwoByte(cx, linearStr)) { + if (!linearChars.initTwoByte(cx, str)) { return nullptr; } - const char16_t* chars = linearChars.twoByteRange().begin().get(); - SourceText source; - if (!source.init(cx, chars, len, SourceOwnership::Borrowed)) { + if (!source.initMaybeBorrowed(cx, linearChars)) { return nullptr; } diff --git a/js/src/debugger/Object.cpp b/js/src/debugger/Object.cpp index 92266e1b4c3e..0b40f96e76a7 100644 --- a/js/src/debugger/Object.cpp +++ b/js/src/debugger/Object.cpp @@ -1287,14 +1287,12 @@ bool DebuggerObject::CallData::createSource() { compileOptions.setIntroductionType("inlineScript"); } - Vector textChars(cx); - if (!CopyStringToVector(cx, text, textChars)) { + AutoStableStringChars linearChars(cx); + if (!linearChars.initTwoByte(cx, text)) { return false; } - JS::SourceText srcBuf; - if (!srcBuf.init(cx, textChars.begin(), text->length(), - JS::SourceOwnership::Borrowed)) { + if (!srcBuf.initMaybeBorrowed(cx, linearChars)) { return false; } diff --git a/js/src/shell/ModuleLoader.cpp b/js/src/shell/ModuleLoader.cpp index e95341eacf89..058248bc5956 100644 --- a/js/src/shell/ModuleLoader.cpp +++ b/js/src/shell/ModuleLoader.cpp @@ -469,15 +469,13 @@ JSObject* ModuleLoader::loadAndParse(JSContext* cx, HandleString pathArg) { return nullptr; } - JS::AutoStableStringChars stableChars(cx); - if (!stableChars.initTwoByte(cx, source)) { + JS::AutoStableStringChars linearChars(cx); + if (!linearChars.initTwoByte(cx, source)) { return nullptr; } - const char16_t* chars = stableChars.twoByteRange().begin().get(); JS::SourceText srcBuf; - if (!srcBuf.init(cx, chars, source->length(), - JS::SourceOwnership::Borrowed)) { + if (!srcBuf.initMaybeBorrowed(cx, linearChars)) { return nullptr; } diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 904b63e6dfcd..41e2088723fc 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -2409,15 +2409,13 @@ static bool Evaluate(JSContext* cx, unsigned argc, Value* vp) { return false; } } else { - AutoStableStringChars codeChars(cx); - if (!codeChars.initTwoByte(cx, code)) { + AutoStableStringChars linearChars(cx); + if (!linearChars.initTwoByte(cx, code)) { return false; } - mozilla::Range chars = codeChars.twoByteRange(); JS::SourceText srcBuf; - if (!srcBuf.init(cx, chars.begin().get(), chars.length(), - JS::SourceOwnership::Borrowed)) { + if (!srcBuf.initMaybeBorrowed(cx, linearChars)) { return false; } @@ -2629,14 +2627,13 @@ static bool Run(JSContext* cx, unsigned argc, Value* vp) { return false; } - AutoStableStringChars chars(cx); - if (!chars.initTwoByte(cx, str)) { + AutoStableStringChars linearChars(cx); + if (!linearChars.initTwoByte(cx, str)) { return false; } JS::SourceText srcBuf; - if (!srcBuf.init(cx, chars.twoByteRange().begin().get(), str->length(), - JS::SourceOwnership::Borrowed)) { + if (!srcBuf.initMaybeBorrowed(cx, linearChars)) { return false; } @@ -4892,15 +4889,13 @@ static bool ParseModule(JSContext* cx, unsigned argc, Value* vp) { } options.setModule(); - AutoStableStringChars stableChars(cx); - if (!stableChars.initTwoByte(cx, scriptContents)) { + AutoStableStringChars linearChars(cx); + if (!linearChars.initTwoByte(cx, scriptContents)) { return false; } - const char16_t* chars = stableChars.twoByteRange().begin().get(); JS::SourceText srcBuf; - if (!srcBuf.init(cx, chars, scriptContents->length(), - JS::SourceOwnership::Borrowed)) { + if (!srcBuf.initMaybeBorrowed(cx, linearChars)) { return false; } @@ -8195,13 +8190,12 @@ static bool EntryPoints(JSContext* cx, unsigned argc, Value* vp) { return false; } - AutoStableStringChars stableChars(cx); - if (!stableChars.initTwoByte(cx, codeString)) { + AutoStableStringChars linearChars(cx); + if (!linearChars.initTwoByte(cx, codeString)) { return false; } JS::SourceText srcBuf; - if (!srcBuf.init(cx, stableChars.twoByteRange().begin().get(), - codeString->length(), JS::SourceOwnership::Borrowed)) { + if (!srcBuf.initMaybeBorrowed(cx, linearChars)) { return false; } diff --git a/js/src/vm/JSFunction.cpp b/js/src/vm/JSFunction.cpp index a025a886016c..ab2f58a0b990 100644 --- a/js/src/vm/JSFunction.cpp +++ b/js/src/vm/JSFunction.cpp @@ -1675,17 +1675,13 @@ static bool CreateDynamicFunction(JSContext* cx, const CallArgs& args, } // Steps 7.a-b, 8.a-b, 9.a-b, 16-28. - AutoStableStringChars stableChars(cx); - if (!stableChars.initTwoByte(cx, functionText)) { + AutoStableStringChars linearChars(cx); + if (!linearChars.initTwoByte(cx, functionText)) { return false; } - mozilla::Range chars = stableChars.twoByteRange(); - SourceOwnership ownership = stableChars.maybeGiveOwnershipToCaller() - ? SourceOwnership::TakeOwnership - : SourceOwnership::Borrowed; SourceText srcBuf; - if (!srcBuf.init(cx, chars.begin().get(), chars.length(), ownership)) { + if (!srcBuf.initMaybeBorrowed(cx, linearChars)) { return false; } diff --git a/js/src/wasm/AsmJS.cpp b/js/src/wasm/AsmJS.cpp index d74de915718e..192528ed1d85 100644 --- a/js/src/wasm/AsmJS.cpp +++ b/js/src/wasm/AsmJS.cpp @@ -7009,18 +7009,13 @@ static bool HandleInstantiationFailure(JSContext* cx, CallArgs args, options.setForceStrictMode(); } - AutoStableStringChars stableChars(cx); - if (!stableChars.initTwoByte(cx, src)) { + AutoStableStringChars linearChars(cx); + if (!linearChars.initTwoByte(cx, src)) { return false; } SourceText srcBuf; - - const char16_t* chars = stableChars.twoByteRange().begin().get(); - SourceOwnership ownership = stableChars.maybeGiveOwnershipToCaller() - ? SourceOwnership::TakeOwnership - : SourceOwnership::Borrowed; - if (!srcBuf.init(cx, chars, end - begin, ownership)) { + if (!srcBuf.initMaybeBorrowed(cx, linearChars)) { return false; }