From 1513233e8f5d3259a69fc4ab14b4b96e1fb8232a Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Tue, 14 Jan 2020 18:02:47 +0000 Subject: [PATCH] Bug 1606084 - Add RegExp support to ValueToSource fallback. r=arai Differential Revision: https://phabricator.services.mozilla.com/D59685 --HG-- extra : moz-landing-system : lando --- js/src/jit-test/tests/basic/valuetosource.js | 2 ++ js/src/vm/CommonPropertyNames.h | 1 + js/src/vm/ToSource.cpp | 13 +++++++++++++ 3 files changed, 16 insertions(+) diff --git a/js/src/jit-test/tests/basic/valuetosource.js b/js/src/jit-test/tests/basic/valuetosource.js index 01ed603a26f3..82527b979aa0 100644 --- a/js/src/jit-test/tests/basic/valuetosource.js +++ b/js/src/jit-test/tests/basic/valuetosource.js @@ -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) { diff --git a/js/src/vm/CommonPropertyNames.h b/js/src/vm/CommonPropertyNames.h index 54c9f1be9c4a..e1adc393d608 100644 --- a/js/src/vm/CommonPropertyNames.h +++ b/js/src/vm/CommonPropertyNames.h @@ -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") \ diff --git a/js/src/vm/ToSource.cpp b/js/src/vm/ToSource.cpp index d489633fc11c..07eb4f12a48f 100644 --- a/js/src/vm/ToSource.cpp +++ b/js/src/vm/ToSource.cpp @@ -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()) { + FixedInvokeArgs<0> args(cx); + RootedValue rval(cx); + if (!CallSelfHostedFunction(cx, cx->names().RegExpToString, v, args, + &rval)) { + return nullptr; + } + return ToString(cx, rval); + } + return ObjectToSource(cx, obj); }