From d676a8001e7f5239f1924bd1563c317366a027ca Mon Sep 17 00:00:00 2001 From: "Nicolas B. Pierron" Date: Wed, 10 May 2017 13:42:08 +0000 Subject: [PATCH] Bug 1351357 - Use the ReadOnlyCompileOptions from the HelperThread while decoding RegExp. r=bhackett --- js/src/frontend/Parser.cpp | 2 +- js/src/jsapi.cpp | 8 ++++---- js/src/vm/RegExpObject.cpp | 25 +++++++++++++++++-------- js/src/vm/RegExpObject.h | 4 ++-- js/src/vm/SelfHosting.cpp | 3 ++- js/src/vm/StructuredClone.cpp | 2 +- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 8af7ad8310d6..d9b9604aa11b 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -9387,7 +9387,7 @@ Parser::newRegExp() RegExpFlag flags = tokenStream.currentToken().regExpFlags(); Rooted reobj(context); - reobj = RegExpObject::create(context, chars, length, flags, &tokenStream, alloc); + reobj = RegExpObject::create(context, chars, length, flags, nullptr, &tokenStream, alloc); if (!reobj) return null(); diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 9cb45f8d80fa..6872c4d72f7c 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -6095,8 +6095,8 @@ JS_NewRegExpObject(JSContext* cx, const char* bytes, size_t length, unsigned fla if (!chars) return nullptr; - RegExpObject* reobj = RegExpObject::create(cx, chars, length, - RegExpFlag(flags), nullptr, cx->tempLifoAlloc()); + RegExpObject* reobj = RegExpObject::create(cx, chars, length, RegExpFlag(flags), + nullptr, nullptr, cx->tempLifoAlloc()); return reobj; } @@ -6105,8 +6105,8 @@ JS_NewUCRegExpObject(JSContext* cx, const char16_t* chars, size_t length, unsign { AssertHeapIsIdle(); CHECK_REQUEST(cx); - return RegExpObject::create(cx, chars, length, - RegExpFlag(flags), nullptr, cx->tempLifoAlloc()); + return RegExpObject::create(cx, chars, length, RegExpFlag(flags), + nullptr, nullptr, cx->tempLifoAlloc()); } JS_PUBLIC_API(bool) diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp index 04fea4628794..aeb60e9563d2 100644 --- a/js/src/vm/RegExpObject.cpp +++ b/js/src/vm/RegExpObject.cpp @@ -238,24 +238,29 @@ const Class RegExpObject::protoClass_ = { RegExpObject* RegExpObject::create(JSContext* cx, const char16_t* chars, size_t length, RegExpFlag flags, - TokenStream* tokenStream, LifoAlloc& alloc) + const ReadOnlyCompileOptions* options, TokenStream* tokenStream, + LifoAlloc& alloc) { RootedAtom source(cx, AtomizeChars(cx, chars, length)); if (!source) return nullptr; - return create(cx, source, flags, tokenStream, alloc); + return create(cx, source, flags, options, tokenStream, alloc); } RegExpObject* RegExpObject::create(JSContext* cx, HandleAtom source, RegExpFlag flags, - TokenStream* tokenStream, LifoAlloc& alloc) + const ReadOnlyCompileOptions* options, TokenStream* tokenStream, + LifoAlloc& alloc) { Maybe dummyOptions; + if (!tokenStream && !options) { + dummyOptions.emplace(cx); + options = dummyOptions.ptr(); + } Maybe dummyTokenStream; if (!tokenStream) { - dummyOptions.emplace(cx); - dummyTokenStream.emplace(cx, *dummyOptions, + dummyTokenStream.emplace(cx, *options, (const char16_t*) nullptr, 0, (frontend::StrictModeGetter*) nullptr); tokenStream = dummyTokenStream.ptr(); @@ -1457,8 +1462,11 @@ js::XDRScriptRegExpObject(XDRState* xdr, MutableHandle objp return false; if (mode == XDR_DECODE) { RegExpFlag flags = RegExpFlag(flagsword); - RegExpObject* reobj = RegExpObject::create(xdr->cx(), source, flags, nullptr, - xdr->lifoAlloc()); + const ReadOnlyCompileOptions* options = nullptr; + if (xdr->hasOptions()) + options = &xdr->options(); + RegExpObject* reobj = RegExpObject::create(xdr->cx(), source, flags, + options, nullptr, xdr->lifoAlloc()); if (!reobj) return false; @@ -1481,7 +1489,8 @@ js::CloneScriptRegExpObject(JSContext* cx, RegExpObject& reobj) RootedAtom source(cx, reobj.getSource()); cx->markAtom(source); - return RegExpObject::create(cx, source, reobj.getFlags(), nullptr, cx->tempLifoAlloc()); + return RegExpObject::create(cx, source, reobj.getFlags(), + nullptr, nullptr, cx->tempLifoAlloc()); } JS_FRIEND_API(bool) diff --git a/js/src/vm/RegExpObject.h b/js/src/vm/RegExpObject.h index af6663a1e6ce..2ffd67a5fbe1 100644 --- a/js/src/vm/RegExpObject.h +++ b/js/src/vm/RegExpObject.h @@ -74,11 +74,11 @@ class RegExpObject : public NativeObject static RegExpObject* create(JSContext* cx, const char16_t* chars, size_t length, RegExpFlag flags, - frontend::TokenStream* ts, LifoAlloc& alloc); + const ReadOnlyCompileOptions* options, frontend::TokenStream* ts, LifoAlloc& alloc); static RegExpObject* create(JSContext* cx, HandleAtom atom, RegExpFlag flags, - frontend::TokenStream* ts, LifoAlloc& alloc); + const ReadOnlyCompileOptions* options, frontend::TokenStream* ts, LifoAlloc& alloc); /* * Compute the initial shape to associate with fresh RegExp objects, diff --git a/js/src/vm/SelfHosting.cpp b/js/src/vm/SelfHosting.cpp index f01a1816bb8d..16cc66ccedbe 100644 --- a/js/src/vm/SelfHosting.cpp +++ b/js/src/vm/SelfHosting.cpp @@ -3061,7 +3061,8 @@ CloneObject(JSContext* cx, HandleNativeObject selfHostedObject) RegExpObject& reobj = selfHostedObject->as(); RootedAtom source(cx, reobj.getSource()); MOZ_ASSERT(source->isPermanentAtom()); - clone = RegExpObject::create(cx, source, reobj.getFlags(), nullptr, cx->tempLifoAlloc()); + clone = RegExpObject::create(cx, source, reobj.getFlags(), + nullptr, nullptr, cx->tempLifoAlloc()); } else if (selfHostedObject->is()) { clone = JS::NewDateObject(cx, selfHostedObject->as().clippedTime()); } else if (selfHostedObject->is()) { diff --git a/js/src/vm/StructuredClone.cpp b/js/src/vm/StructuredClone.cpp index 352c78e1a645..08c52236ca63 100644 --- a/js/src/vm/StructuredClone.cpp +++ b/js/src/vm/StructuredClone.cpp @@ -2126,7 +2126,7 @@ JSStructuredCloneReader::startRead(MutableHandleValue vp) if (!atom) return false; - RegExpObject* reobj = RegExpObject::create(context(), atom, flags, nullptr, + RegExpObject* reobj = RegExpObject::create(context(), atom, flags, nullptr, nullptr, context()->tempLifoAlloc()); if (!reobj) return false;