зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1606084 - Add RegExp support to ValueToSource fallback. r=arai
Differential Revision: https://phabricator.services.mozilla.com/D59685 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
96287c698e
Коммит
1513233e8f
|
@ -20,6 +20,8 @@ const TEST_CASES = [
|
|||
this.name = "X";
|
||||
}
|
||||
}, `(new X("msg", "file", 1))`],
|
||||
[/a(b)c/, `/a(b)c/`],
|
||||
[/abc/gi, `/abc/gi`],
|
||||
]
|
||||
|
||||
for (let [actual, expected] of TEST_CASES) {
|
||||
|
|
|
@ -366,6 +366,7 @@
|
|||
MACRO(RegExpSearcher, RegExpSearcher, "RegExpSearcher") \
|
||||
MACRO(RegExpStringIterator, RegExpStringIterator, "RegExp String Iterator") \
|
||||
MACRO(RegExpTester, RegExpTester, "RegExpTester") \
|
||||
MACRO(RegExpToString, RegExpToString, "$RegExpToString") \
|
||||
MACRO(RegExp_prototype_Exec, RegExp_prototype_Exec, "RegExp_prototype_Exec") \
|
||||
MACRO(region, region, "region") \
|
||||
MACRO(register, register_, "register") \
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
#include "vm/JSContext.h" // JSContext
|
||||
#include "vm/JSFunction.h" // JSFunction, FunctionToString
|
||||
#include "vm/Printer.h" // QuoteString
|
||||
#include "vm/RegExpObject.h" // RegExpObject
|
||||
#include "vm/SelfHosting.h" // CallSelfHostedFunction
|
||||
#include "vm/Stack.h" // FixedInvokeArgs
|
||||
#include "vm/StringType.h" // NewStringCopy{N,Z}, ToString
|
||||
#include "vm/SymbolType.h" // Symbol
|
||||
|
||||
|
@ -132,5 +135,15 @@ JSString* js::ValueToSource(JSContext* cx, HandleValue v) {
|
|||
return ErrorToSource(cx, obj);
|
||||
}
|
||||
|
||||
if (obj->is<RegExpObject>()) {
|
||||
FixedInvokeArgs<0> args(cx);
|
||||
RootedValue rval(cx);
|
||||
if (!CallSelfHostedFunction(cx, cx->names().RegExpToString, v, args,
|
||||
&rval)) {
|
||||
return nullptr;
|
||||
}
|
||||
return ToString<CanGC>(cx, rval);
|
||||
}
|
||||
|
||||
return ObjectToSource(cx, obj);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче