Skip to content

Commit

Permalink
Enabling padStart and padEnd by default on.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akroshg committed Jul 8, 2016
1 parent 0cce960 commit 995ab5f
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 97 deletions.
10 changes: 0 additions & 10 deletions lib/Common/ConfigFlagsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/Runtime/Base/ThreadConfigFlagsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 4 additions & 10 deletions lib/Runtime/Library/JavascriptLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Runtime/Library/JavascriptString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,10 @@ namespace Js
{
fillerString = argStr;
}
else
{
return mainString;
}
}

if (fillerString == nullptr)
Expand Down
2 changes: 1 addition & 1 deletion test/es7/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<test>
<default>
<files>stringpad.js</files>
<compile-flags>-ES7Builtins -args summary -endargs</compile-flags>
<compile-flags>-args summary -endargs</compile-flags>
</default>
</test>
<test>
Expand Down
150 changes: 75 additions & 75 deletions test/es7/stringpad.js
Original file line number Diff line number Diff line change
@@ -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" });

0 comments on commit 995ab5f

Please # to comment.