From e2f1c26982f57411571c4ce41d02f7d56501b208 Mon Sep 17 00:00:00 2001 From: bmeurer Date: Tue, 15 Sep 2015 07:32:25 -0700 Subject: [PATCH] [es6] Move builtin constructors for primitives to strict mode. The ES6 specification says that "Built-in functions that are ECMAScript function objects must be strict mode functions", which in particular means that you can never test for them using the "caller" field of a sloppy mode function. CQ_INCLUDE_TRYBOTS=tryserver.v8:v8_linux_layout_dbg,v8_linux_nosnap_dbg R=mstarzinger@chromium.org BUG=v8:105 LOG=n Review URL: https://codereview.chromium.org/1347663002 Cr-Commit-Position: refs/heads/master@{#30750} --- src/string.js | 2 ++ src/v8natives.js | 4 ++++ test/mjsunit/regress/regress-105.js | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/string.js b/src/string.js index a8a9e8bd3..e6671eec1 100644 --- a/src/string.js +++ b/src/string.js @@ -36,6 +36,8 @@ utils.Import(function(from) { //------------------------------------------------------------------- function StringConstructor(x) { + // TODO(bmeurer): Move this to toplevel. + "use strict"; if (%_ArgumentsLength() == 0) x = ''; if (%_IsConstructCall()) { %_SetValueOf(this, TO_STRING_INLINE(x)); diff --git a/src/v8natives.js b/src/v8natives.js index a9306003b..6106ae914 100644 --- a/src/v8natives.js +++ b/src/v8natives.js @@ -1341,6 +1341,8 @@ utils.InstallFunctions(GlobalObject, DONT_ENUM, [ // Boolean function BooleanConstructor(x) { + // TODO(bmeurer): Move this to toplevel. + "use strict"; if (%_IsConstructCall()) { %_SetValueOf(this, ToBoolean(x)); } else { @@ -1390,6 +1392,8 @@ utils.InstallFunctions(GlobalBoolean.prototype, DONT_ENUM, [ // Number function NumberConstructor(x) { + // TODO(bmeurer): Move this to toplevel. + "use strict"; var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x); if (%_IsConstructCall()) { %_SetValueOf(this, value); diff --git a/test/mjsunit/regress/regress-105.js b/test/mjsunit/regress/regress-105.js index 8b8030ffe..877cb8231 100644 --- a/test/mjsunit/regress/regress-105.js +++ b/test/mjsunit/regress/regress-105.js @@ -26,12 +26,12 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. var custom_valueOf = function() { - assertEquals(Number, custom_valueOf.caller); + assertEquals(null, custom_valueOf.caller); return 2; } var custom_toString = function() { - assertEquals(String, custom_toString.caller); + assertEquals(null, custom_toString.caller); return "I used to be an adventurer like you"; } -- 2.34.1