diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 8b54e1a5152..00c3b4dedc1 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -2958,7 +2958,7 @@ EvalInWorker(JSContext *cx, unsigned argc, jsval *vp) jschar *chars = (jschar *) js_malloc(str->length() * sizeof(jschar)); if (!chars) return false; - PodCopy(chars, str->chars(), str->length()); + CopyChars(chars, *str); WorkerInput *input = js_new(cx->runtime(), chars, str->length()); if (!input) @@ -4528,6 +4528,11 @@ ToLatin1(JSContext *cx, unsigned argc, Value *vp) return true; } + if (args[0].toString()->hasLatin1Chars()) { + args.rval().set(args[0]); + return true; + } + JSLinearString *s = &args[0].toString()->asLinear(); s->debugUnsafeConvertToLatin1(); args.rval().setString(s); @@ -6313,6 +6318,7 @@ main(int argc, char **argv, char **envp) "to test JIT codegen (no-op on platforms other than x86 and x64).") || !op.addBoolOption('\0', "fuzzing-safe", "Don't expose functions that aren't safe for " "fuzzers to call") + || !op.addBoolOption('\0', "latin1-strings", "Enable Latin1 strings (default: off)") #ifdef DEBUG || !op.addBoolOption('\0', "dump-entrained-variables", "Print variables which are " "unnecessarily entrained by inner functions") @@ -6385,6 +6391,11 @@ main(int argc, char **argv, char **envp) #endif // DEBUG + // Set this option before initializing the JSRuntime, so that Latin1 strings + // are used for strings allocated during initialization. + if (op.getBoolOption("latin1-strings")) + js::EnableLatin1Strings = true; + #ifdef JS_THREADSAFE // The fake thread count must be set before initializing the Runtime, // which spins up the thread pool. diff --git a/js/src/tests/lib/tests.py b/js/src/tests/lib/tests.py index a9e35d5a1d4..ad2b96e56e2 100644 --- a/js/src/tests/lib/tests.py +++ b/js/src/tests/lib/tests.py @@ -14,7 +14,7 @@ TBPL_FLAGS = [ [], # no flags, normal baseline and ion ['--ion-eager', '--ion-offthread-compile=off'], # implies --baseline-eager ['--ion-eager', '--ion-offthread-compile=off', '--ion-check-range-analysis', '--no-sse3'], - ['--baseline-eager'], + ['--baseline-eager', '--latin1-strings'], ['--baseline-eager', '--no-fpu'], ['--no-baseline', '--no-ion'], ] diff --git a/js/src/vm/String.cpp b/js/src/vm/String.cpp index df573465cb7..969a92e6d56 100644 --- a/js/src/vm/String.cpp +++ b/js/src/vm/String.cpp @@ -868,6 +868,8 @@ AutoStableStringChars::initTwoByte(JSContext *cx, JSString *s) return true; } +bool js::EnableLatin1Strings = false; + #ifdef DEBUG void JSAtom::dump() diff --git a/js/src/vm/String.h b/js/src/vm/String.h index ce4ead943f8..a08463d63ae 100644 --- a/js/src/vm/String.h +++ b/js/src/vm/String.h @@ -519,9 +519,6 @@ class JSString : public js::gc::BarrieredCell void operator=(const JSString &other) MOZ_DELETE; }; -/* Temporary flag to enable Latin1 strings (bug 998392). */ -static const bool EnableLatin1Strings = false; - class JSRope : public JSString { template @@ -1002,6 +999,9 @@ JS_STATIC_ASSERT(sizeof(JSAtom) == sizeof(JSString)); namespace js { +/* Temporary flag to enable Latin1 strings (bug 998392). */ +extern bool EnableLatin1Strings; + /* * Thread safe RAII wrapper for inspecting the contents of JSStrings. The * thread safe operations such as |getCharsNonDestructive| require allocation