From 995ab5f6d13ac976f621df58fd0322e552394559 Mon Sep 17 00:00:00 2001 From: Akrosh Gandhi Date: Thu, 7 Jul 2016 17:41:32 -0700 Subject: [PATCH] Enabling padStart and padEnd by default on. Apart from enabling it, I found that spec for padStart/padEnd got changed where , 8. If filler is the empty String, return S. (https://tc39.github.io/ecma262/#sec-string.prototype.padstart) fixed that and updated the test. test262 is fully passed for these two APIs. --- lib/Common/ConfigFlagsList.h | 10 -- lib/Runtime/Base/ThreadConfigFlagsList.h | 1 - lib/Runtime/Library/JavascriptLibrary.cpp | 14 +- lib/Runtime/Library/JavascriptString.cpp | 4 + test/es7/rlexe.xml | 2 +- test/es7/stringpad.js | 150 +++++++++++----------- 6 files changed, 84 insertions(+), 97 deletions(-) diff --git a/lib/Common/ConfigFlagsList.h b/lib/Common/ConfigFlagsList.h index 37a89b3cc66..be22cc16679 100644 --- a/lib/Common/ConfigFlagsList.h +++ b/lib/Common/ConfigFlagsList.h @@ -566,12 +566,6 @@ PHASE(All) #else #define DEFAULT_CONFIG_ES7AsyncAwait (false) #endif -#ifdef COMPILE_DISABLE_ES7Builtins - // If ES7Builtins needs to be disabled by compile flag, DEFAULT_CONFIG_ES7Builtins should be false - #define DEFAULT_CONFIG_ES7Builtins (false) -#else - #define DEFAULT_CONFIG_ES7Builtins (false) -#endif #define DEFAULT_CONFIG_ES7ExponentionOperator (true) #define DEFAULT_CONFIG_ES7TrailingComma (true) #define DEFAULT_CONFIG_ES7ValuesEntries (true) @@ -953,10 +947,6 @@ FLAGPR_REGOVR_EXP(Boolean, ES6, ES6FunctionNameFull , "Enable ES6 Full functi FLAGPR (Boolean, ES6, ES6Generators , "Enable ES6 generators" , DEFAULT_CONFIG_ES6Generators) FLAGPR (Boolean, ES6, ES7ExponentiationOperator, "Enable ES7 exponentiation operator (**)" , DEFAULT_CONFIG_ES7ExponentionOperator) -#ifndef COMPILE_DISABLE_ES7Builtins - #define COMPILE_DISABLE_ES7Builtins 0 -#endif -FLAGPR_REGOVR_EXP(Boolean, ES6, ES7Builtins , "Enable ES7 built-ins" , DEFAULT_CONFIG_ES7Builtins) FLAGPR (Boolean, ES6, ES7ValuesEntries , "Enable ES7 Object.values and Object.entries" , DEFAULT_CONFIG_ES7ValuesEntries) FLAGPR (Boolean, ES6, ES7TrailingComma , "Enable ES7 trailing comma in function" , DEFAULT_CONFIG_ES7TrailingComma) #ifndef COMPILE_DISABLE_ES6IsConcatSpreadable diff --git a/lib/Runtime/Base/ThreadConfigFlagsList.h b/lib/Runtime/Base/ThreadConfigFlagsList.h index 7e56d486f1a..6495e40d4c5 100644 --- a/lib/Runtime/Base/ThreadConfigFlagsList.h +++ b/lib/Runtime/Base/ThreadConfigFlagsList.h @@ -20,7 +20,6 @@ FLAG_RELEASE(IsES6FunctionNameFullEnabled, ES6FunctionNameFull) FLAG_RELEASE(IsES6GeneratorsEnabled, ES6Generators) FLAG_RELEASE(IsES7ExponentiationOperatorEnabled, ES7ExponentiationOperator) FLAG_RELEASE(IsES7TrailingCommaEnabled, ES7TrailingComma) -FLAG_RELEASE(IsES7BuiltinsEnabled, ES7Builtins) FLAG_RELEASE(IsES7ValuesEntriesEnabled, ES7ValuesEntries) FLAG_RELEASE(IsES6IsConcatSpreadableEnabled, ES6IsConcatSpreadable) FLAG_RELEASE(IsES6MathExtensionsEnabled, ES6Math) diff --git a/lib/Runtime/Library/JavascriptLibrary.cpp b/lib/Runtime/Library/JavascriptLibrary.cpp index 69deaa67912..f649c528876 100644 --- a/lib/Runtime/Library/JavascriptLibrary.cpp +++ b/lib/Runtime/Library/JavascriptLibrary.cpp @@ -4090,11 +4090,8 @@ namespace Js library->AddFunctionToLibraryObjectWithName(stringPrototype, PropertyIds::_symbolIterator, PropertyIds::_RuntimeFunctionNameId_iterator, &JavascriptString::EntryInfo::SymbolIterator, 0); - if (scriptContext->GetConfig()->IsES7BuiltinsEnabled()) - { - builtinFuncs[BuiltinFunction::String_PadStart] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::padStart, &JavascriptString::EntryInfo::PadStart, 1); - builtinFuncs[BuiltinFunction::String_PadEnd] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::padEnd, &JavascriptString::EntryInfo::PadEnd, 1); - } + builtinFuncs[BuiltinFunction::String_PadStart] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::padStart, &JavascriptString::EntryInfo::PadStart, 1); + builtinFuncs[BuiltinFunction::String_PadEnd] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::padEnd, &JavascriptString::EntryInfo::PadEnd, 1); DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext)); @@ -7145,11 +7142,8 @@ namespace Js REG_OBJECTS_LIB_FUNC2(_symbolIterator, _u("[Symbol.iterator]"), JavascriptString::EntrySymbolIterator); - if (config.IsES7BuiltinsEnabled()) - { - REG_OBJECTS_LIB_FUNC(padStart, JavascriptString::EntryPadStart); - REG_OBJECTS_LIB_FUNC(padEnd, JavascriptString::EntryPadEnd); - } + REG_OBJECTS_LIB_FUNC(padStart, JavascriptString::EntryPadStart); + REG_OBJECTS_LIB_FUNC(padEnd, JavascriptString::EntryPadEnd); return hr; } diff --git a/lib/Runtime/Library/JavascriptString.cpp b/lib/Runtime/Library/JavascriptString.cpp index d03dd458eb8..200fae06631 100644 --- a/lib/Runtime/Library/JavascriptString.cpp +++ b/lib/Runtime/Library/JavascriptString.cpp @@ -2055,6 +2055,10 @@ namespace Js { fillerString = argStr; } + else + { + return mainString; + } } if (fillerString == nullptr) diff --git a/test/es7/rlexe.xml b/test/es7/rlexe.xml index 955da03a36c..98ea84b0862 100644 --- a/test/es7/rlexe.xml +++ b/test/es7/rlexe.xml @@ -29,7 +29,7 @@ stringpad.js - -ES7Builtins -args summary -endargs + -args summary -endargs diff --git a/test/es7/stringpad.js b/test/es7/stringpad.js index 1943d1ec2ba..b057a1cbc82 100644 --- a/test/es7/stringpad.js +++ b/test/es7/stringpad.js @@ -1,75 +1,75 @@ -//------------------------------------------------------------------------------------------------------- -// Copyright (C) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. -//------------------------------------------------------------------------------------------------------- - -WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); - -var tests = [ - { - name: "String.prototype.padStart/padEnd should exist and constructed properly", - body: function () { - assert.isTrue(String.prototype.hasOwnProperty('padStart'), "String.prototype should have a padStart method"); - assert.isTrue(String.prototype.hasOwnProperty('padEnd'), "String.prototype should have a padEnd method"); - assert.areEqual(1, String.prototype.padStart.length, "padStart method takes one argument"); - assert.areEqual(1, String.prototype.padEnd.length, "padEnd method takes one argument"); - assert.areEqual("padStart", String.prototype.padStart.name, "padStart.name is 'padStart'"); - assert.areEqual("padEnd", String.prototype.padEnd.name, "padEnd.name is 'padEnd'"); - - var descriptor = Object.getOwnPropertyDescriptor(String.prototype, 'padStart'); - assert.isTrue(descriptor.writable, "writable(padStart) must be true"); - assert.isFalse(descriptor.enumerable, "enumerable(padStart) must be false"); - assert.isTrue(descriptor.configurable, "configurable(padStart) must be true"); - - descriptor = Object.getOwnPropertyDescriptor(String.prototype, 'padEnd'); - assert.isTrue(descriptor.writable, "writable(padEnd) must be true"); - assert.isFalse(descriptor.enumerable, "enumerable(padEnd) must be false"); - assert.isTrue(descriptor.configurable, "configurable(padEnd) must be true"); - } - }, - { - name: "String.prototype.padStart functionality", - body: function () { - assert.areEqual('foo'.padStart(), 'foo', "No arguments to padStart will not affect string"); - assert.areEqual('foo'.padStart(1), 'foo', "No padding added if maxLength (first argument) is less than the length of actual string"); - assert.areEqual('foo'.padStart(-1), 'foo', "No padding added if maxLength (first argument), negative, is less than the length of actual string"); - assert.areEqual('foo'.padStart(3), 'foo', "No padding added if maxLength (first argument) is equal to the length of actual string"); - assert.areEqual('foo'.padStart(4), ' foo', "String with one ' ' (SPACE) as pad is returned"); - assert.areEqual('foo'.padStart(10), ' foo', "String of length 10, with spaces filled as padding, is returned"); - assert.areEqual('foo'.padStart(10, ''), ' foo', "Empty fillString - string of length 10, with spaces filled as padding, is returned"); - assert.areEqual('foo'.padStart(10, undefined), ' foo', "'undefined' fillString - string of length 10, with spaces filled as padding, is returned"); - assert.areEqual('foo'.padStart(10, ' '), ' foo', "fillString as one space - string of length 10, with spaces filled as padding, is returned"); - assert.areEqual('foo'.padStart(4, '123'), '1foo', "String of length 4, with only one character from fillString added as a padding, is returned"); - assert.areEqual('foo'.padStart(10, '123'), '1231231foo', "String of length 10, with repeatedly adding characters from fillString to create enough padding, is returned"); - } - }, - { - name: "String.prototype.padEnd functionality", - body: function () { - assert.areEqual('foo'.padEnd(), 'foo', "No arguments to padEnd will not affect string"); - assert.areEqual('foo'.padEnd(1), 'foo', "No padding added if maxLength (first argument) is less than the length of actual string"); - assert.areEqual('foo'.padEnd(-1), 'foo', "No padding added if maxLength (first argument), negative, is less than the length of actual string"); - assert.areEqual('foo'.padEnd(3), 'foo', "No padding added if maxLength (first argument) is equal to the length of actual string"); - assert.areEqual('foo'.padEnd(4), 'foo ', "String with one ' ' (SPACE) as pad is returned"); - assert.areEqual('foo'.padEnd(10), 'foo ', "String of length 10, with spaces filled as padding, is returned"); - assert.areEqual('foo'.padEnd(10, ''), 'foo ', "Empty fillString - string of length 10, with spaces filled as padding, is returned"); - assert.areEqual('foo'.padEnd(10, undefined), 'foo ', "'undefined' fillString - string of length 10, with spaces filled as padding, is returned"); - assert.areEqual('foo'.padEnd(10, ' '), 'foo ', "fillString as one space - string of length 10, with spaces filled as padding, is returned"); - assert.areEqual('foo'.padEnd(4, '123'), 'foo1', "String of length 4, with only one character from fillString added as a padding, is returned"); - assert.areEqual('foo'.padEnd(10, '123'), 'foo1231231', "String of length 10, with repeatedly adding characters from fillString to create enough padding, is returned"); - } - }, - { - name: "String.prototype.padStart OOM scenario", - body: function () { - try { - 'foo'.padStart(2147483647); - } - catch(e) { - assert.areEqual(e.message, "Out of memory", "validating out of memory for maxLength >= int_max"); - } - } - } -]; - -testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" }); +//------------------------------------------------------------------------------------------------------- +// Copyright (C) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- + +WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); + +var tests = [ + { + name: "String.prototype.padStart/padEnd should exist and constructed properly", + body: function () { + assert.isTrue(String.prototype.hasOwnProperty('padStart'), "String.prototype should have a padStart method"); + assert.isTrue(String.prototype.hasOwnProperty('padEnd'), "String.prototype should have a padEnd method"); + assert.areEqual(1, String.prototype.padStart.length, "padStart method takes one argument"); + assert.areEqual(1, String.prototype.padEnd.length, "padEnd method takes one argument"); + assert.areEqual("padStart", String.prototype.padStart.name, "padStart.name is 'padStart'"); + assert.areEqual("padEnd", String.prototype.padEnd.name, "padEnd.name is 'padEnd'"); + + var descriptor = Object.getOwnPropertyDescriptor(String.prototype, 'padStart'); + assert.isTrue(descriptor.writable, "writable(padStart) must be true"); + assert.isFalse(descriptor.enumerable, "enumerable(padStart) must be false"); + assert.isTrue(descriptor.configurable, "configurable(padStart) must be true"); + + descriptor = Object.getOwnPropertyDescriptor(String.prototype, 'padEnd'); + assert.isTrue(descriptor.writable, "writable(padEnd) must be true"); + assert.isFalse(descriptor.enumerable, "enumerable(padEnd) must be false"); + assert.isTrue(descriptor.configurable, "configurable(padEnd) must be true"); + } + }, + { + name: "String.prototype.padStart functionality", + body: function () { + assert.areEqual('foo'.padStart(), 'foo', "No arguments to padStart will not affect string"); + assert.areEqual('foo'.padStart(1), 'foo', "No padding added if maxLength (first argument) is less than the length of actual string"); + assert.areEqual('foo'.padStart(-1), 'foo', "No padding added if maxLength (first argument), negative, is less than the length of actual string"); + assert.areEqual('foo'.padStart(3), 'foo', "No padding added if maxLength (first argument) is equal to the length of actual string"); + assert.areEqual('foo'.padStart(4), ' foo', "String with one ' ' (SPACE) as pad is returned"); + assert.areEqual('foo'.padStart(10), ' foo', "String of length 10, with spaces filled as padding, is returned"); + assert.areEqual('foo'.padStart(10, ''), 'foo', "No padding added if the fillString is empty string"); + assert.areEqual('foo'.padStart(10, undefined), ' foo', "'undefined' fillString - string of length 10, with spaces filled as padding, is returned"); + assert.areEqual('foo'.padStart(10, ' '), ' foo', "fillString as one space - string of length 10, with spaces filled as padding, is returned"); + assert.areEqual('foo'.padStart(4, '123'), '1foo', "String of length 4, with only one character from fillString added as a padding, is returned"); + assert.areEqual('foo'.padStart(10, '123'), '1231231foo', "String of length 10, with repeatedly adding characters from fillString to create enough padding, is returned"); + } + }, + { + name: "String.prototype.padEnd functionality", + body: function () { + assert.areEqual('foo'.padEnd(), 'foo', "No arguments to padEnd will not affect string"); + assert.areEqual('foo'.padEnd(1), 'foo', "No padding added if maxLength (first argument) is less than the length of actual string"); + assert.areEqual('foo'.padEnd(-1), 'foo', "No padding added if maxLength (first argument), negative, is less than the length of actual string"); + assert.areEqual('foo'.padEnd(3), 'foo', "No padding added if maxLength (first argument) is equal to the length of actual string"); + assert.areEqual('foo'.padEnd(4), 'foo ', "String with one ' ' (SPACE) as pad is returned"); + assert.areEqual('foo'.padEnd(10), 'foo ', "String of length 10, with spaces filled as padding, is returned"); + assert.areEqual('foo'.padEnd(10, ''), 'foo', "No padding added if the fillString is empty string"); + assert.areEqual('foo'.padEnd(10, undefined), 'foo ', "'undefined' fillString - string of length 10, with spaces filled as padding, is returned"); + assert.areEqual('foo'.padEnd(10, ' '), 'foo ', "fillString as one space - string of length 10, with spaces filled as padding, is returned"); + assert.areEqual('foo'.padEnd(4, '123'), 'foo1', "String of length 4, with only one character from fillString added as a padding, is returned"); + assert.areEqual('foo'.padEnd(10, '123'), 'foo1231231', "String of length 10, with repeatedly adding characters from fillString to create enough padding, is returned"); + } + }, + { + name: "String.prototype.padStart OOM scenario", + body: function () { + try { + 'foo'.padStart(2147483647); + } + catch(e) { + assert.areEqual(e.message, "Out of memory", "validating out of memory for maxLength >= int_max"); + } + } + } +]; + +testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });