Skip to content

Commit 2e2f466

Browse files
committed
[MERGE #1257 @akroshg] Enabling padStart and padEnd by default on.
Merge pull request #1257 from akroshg:stringpad 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.
2 parents 7732500 + b2fe9c4 commit 2e2f466

File tree

9 files changed

+84
-105
lines changed

9 files changed

+84
-105
lines changed

lib/Common/ConfigFlagsList.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,6 @@ PHASE(All)
566566
#else
567567
#define DEFAULT_CONFIG_ES7AsyncAwait (false)
568568
#endif
569-
#ifdef COMPILE_DISABLE_ES7Builtins
570-
// If ES7Builtins needs to be disabled by compile flag, DEFAULT_CONFIG_ES7Builtins should be false
571-
#define DEFAULT_CONFIG_ES7Builtins (false)
572-
#else
573-
#define DEFAULT_CONFIG_ES7Builtins (false)
574-
#endif
575569
#define DEFAULT_CONFIG_ES7ExponentionOperator (true)
576570
#define DEFAULT_CONFIG_ES7TrailingComma (true)
577571
#define DEFAULT_CONFIG_ES7ValuesEntries (true)
@@ -953,10 +947,6 @@ FLAGPR_REGOVR_EXP(Boolean, ES6, ES6FunctionNameFull , "Enable ES6 Full functi
953947
FLAGPR (Boolean, ES6, ES6Generators , "Enable ES6 generators" , DEFAULT_CONFIG_ES6Generators)
954948
FLAGPR (Boolean, ES6, ES7ExponentiationOperator, "Enable ES7 exponentiation operator (**)" , DEFAULT_CONFIG_ES7ExponentionOperator)
955949

956-
#ifndef COMPILE_DISABLE_ES7Builtins
957-
#define COMPILE_DISABLE_ES7Builtins 0
958-
#endif
959-
FLAGPR_REGOVR_EXP(Boolean, ES6, ES7Builtins , "Enable ES7 built-ins" , DEFAULT_CONFIG_ES7Builtins)
960950
FLAGPR (Boolean, ES6, ES7ValuesEntries , "Enable ES7 Object.values and Object.entries" , DEFAULT_CONFIG_ES7ValuesEntries)
961951
FLAGPR (Boolean, ES6, ES7TrailingComma , "Enable ES7 trailing comma in function" , DEFAULT_CONFIG_ES7TrailingComma)
962952
#ifndef COMPILE_DISABLE_ES6IsConcatSpreadable

lib/Runtime/Base/ThreadConfigFlagsList.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ FLAG_RELEASE(IsES6FunctionNameFullEnabled, ES6FunctionNameFull)
2020
FLAG_RELEASE(IsES6GeneratorsEnabled, ES6Generators)
2121
FLAG_RELEASE(IsES7ExponentiationOperatorEnabled, ES7ExponentiationOperator)
2222
FLAG_RELEASE(IsES7TrailingCommaEnabled, ES7TrailingComma)
23-
FLAG_RELEASE(IsES7BuiltinsEnabled, ES7Builtins)
2423
FLAG_RELEASE(IsES7ValuesEntriesEnabled, ES7ValuesEntries)
2524
FLAG_RELEASE(IsES6IsConcatSpreadableEnabled, ES6IsConcatSpreadable)
2625
FLAG_RELEASE(IsES6MathExtensionsEnabled, ES6Math)

lib/Runtime/Library/JavascriptLibrary.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4090,11 +4090,8 @@ namespace Js
40904090

40914091
library->AddFunctionToLibraryObjectWithName(stringPrototype, PropertyIds::_symbolIterator, PropertyIds::_RuntimeFunctionNameId_iterator, &JavascriptString::EntryInfo::SymbolIterator, 0);
40924092

4093-
if (scriptContext->GetConfig()->IsES7BuiltinsEnabled())
4094-
{
4095-
builtinFuncs[BuiltinFunction::String_PadStart] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::padStart, &JavascriptString::EntryInfo::PadStart, 1);
4096-
builtinFuncs[BuiltinFunction::String_PadEnd] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::padEnd, &JavascriptString::EntryInfo::PadEnd, 1);
4097-
}
4093+
builtinFuncs[BuiltinFunction::String_PadStart] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::padStart, &JavascriptString::EntryInfo::PadStart, 1);
4094+
builtinFuncs[BuiltinFunction::String_PadEnd] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::padEnd, &JavascriptString::EntryInfo::PadEnd, 1);
40984095

40994096
DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
41004097

@@ -7145,11 +7142,8 @@ namespace Js
71457142

71467143
REG_OBJECTS_LIB_FUNC2(_symbolIterator, _u("[Symbol.iterator]"), JavascriptString::EntrySymbolIterator);
71477144

7148-
if (config.IsES7BuiltinsEnabled())
7149-
{
7150-
REG_OBJECTS_LIB_FUNC(padStart, JavascriptString::EntryPadStart);
7151-
REG_OBJECTS_LIB_FUNC(padEnd, JavascriptString::EntryPadEnd);
7152-
}
7145+
REG_OBJECTS_LIB_FUNC(padStart, JavascriptString::EntryPadStart);
7146+
REG_OBJECTS_LIB_FUNC(padEnd, JavascriptString::EntryPadEnd);
71537147

71547148
return hr;
71557149
}

lib/Runtime/Library/JavascriptString.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,10 @@ namespace Js
20552055
{
20562056
fillerString = argStr;
20572057
}
2058+
else
2059+
{
2060+
return mainString;
2061+
}
20582062
}
20592063

20602064
if (fillerString == nullptr)

test/es6/es6_all.baseline

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ FLAG ES6 = 1 - setting child flag ES6Generators = 1
2525
FLAG ES6Generators = 1
2626
FLAG ES6 = 1 - setting child flag ES7ExponentiationOperator = 1
2727
FLAG ES7ExponentiationOperator = 1
28-
FLAG ES6 = 1 - setting child flag ES7Builtins = 1
29-
FLAG ES7Builtins = 1
3028
FLAG ES6 = 1 - setting child flag ES7ValuesEntries = 1
3129
FLAG ES7ValuesEntries = 1
3230
FLAG ES6 = 1 - setting child flag ES7TrailingComma = 1

test/es6/es6_stable.baseline

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ FLAG ES6 = 1 - setting child flag ES6Generators = 1
2525
FLAG ES6Generators = 1
2626
FLAG ES6 = 1 - setting child flag ES7ExponentiationOperator = 1
2727
FLAG ES7ExponentiationOperator = 1
28-
FLAG ES6 = 1 - setting child flag ES7Builtins = 0
29-
FLAG ES7Builtins = 0
3028
FLAG ES6 = 1 - setting child flag ES7ValuesEntries = 1
3129
FLAG ES7ValuesEntries = 1
3230
FLAG ES6 = 1 - setting child flag ES7TrailingComma = 1

test/es6/es6_stable.enable_disable.baseline

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ FLAG ES6 = 1 - setting child flag ES6Generators = 1
2525
FLAG ES6Generators = 1
2626
FLAG ES6 = 1 - setting child flag ES7ExponentiationOperator = 1
2727
FLAG ES7ExponentiationOperator = 1
28-
FLAG ES6 = 1 - setting child flag ES7Builtins = 0
29-
FLAG ES7Builtins = 0
3028
FLAG ES6 = 1 - setting child flag ES7ValuesEntries = 1
3129
FLAG ES7ValuesEntries = 1
3230
FLAG ES6 = 1 - setting child flag ES7TrailingComma = 1
@@ -110,8 +108,6 @@ FLAG ES6 = 0 - setting child flag ES6Generators = 0
110108
FLAG ES6Generators = 0
111109
FLAG ES6 = 0 - setting child flag ES7ExponentiationOperator = 0
112110
FLAG ES7ExponentiationOperator = 0
113-
FLAG ES6 = 0 - setting child flag ES7Builtins = 0
114-
FLAG ES7Builtins = 0
115111
FLAG ES6 = 0 - setting child flag ES7ValuesEntries = 0
116112
FLAG ES7ValuesEntries = 0
117113
FLAG ES6 = 0 - setting child flag ES7TrailingComma = 0

test/es7/rlexe.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<test>
3030
<default>
3131
<files>stringpad.js</files>
32-
<compile-flags>-ES7Builtins -args summary -endargs</compile-flags>
32+
<compile-flags>-args summary -endargs</compile-flags>
3333
</default>
3434
</test>
3535
<test>

test/es7/stringpad.js

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
1-
//-------------------------------------------------------------------------------------------------------
2-
// Copyright (C) Microsoft. All rights reserved.
3-
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4-
//-------------------------------------------------------------------------------------------------------
5-
6-
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
7-
8-
var tests = [
9-
{
10-
name: "String.prototype.padStart/padEnd should exist and constructed properly",
11-
body: function () {
12-
assert.isTrue(String.prototype.hasOwnProperty('padStart'), "String.prototype should have a padStart method");
13-
assert.isTrue(String.prototype.hasOwnProperty('padEnd'), "String.prototype should have a padEnd method");
14-
assert.areEqual(1, String.prototype.padStart.length, "padStart method takes one argument");
15-
assert.areEqual(1, String.prototype.padEnd.length, "padEnd method takes one argument");
16-
assert.areEqual("padStart", String.prototype.padStart.name, "padStart.name is 'padStart'");
17-
assert.areEqual("padEnd", String.prototype.padEnd.name, "padEnd.name is 'padEnd'");
18-
19-
var descriptor = Object.getOwnPropertyDescriptor(String.prototype, 'padStart');
20-
assert.isTrue(descriptor.writable, "writable(padStart) must be true");
21-
assert.isFalse(descriptor.enumerable, "enumerable(padStart) must be false");
22-
assert.isTrue(descriptor.configurable, "configurable(padStart) must be true");
23-
24-
descriptor = Object.getOwnPropertyDescriptor(String.prototype, 'padEnd');
25-
assert.isTrue(descriptor.writable, "writable(padEnd) must be true");
26-
assert.isFalse(descriptor.enumerable, "enumerable(padEnd) must be false");
27-
assert.isTrue(descriptor.configurable, "configurable(padEnd) must be true");
28-
}
29-
},
30-
{
31-
name: "String.prototype.padStart functionality",
32-
body: function () {
33-
assert.areEqual('foo'.padStart(), 'foo', "No arguments to padStart will not affect string");
34-
assert.areEqual('foo'.padStart(1), 'foo', "No padding added if maxLength (first argument) is less than the length of actual string");
35-
assert.areEqual('foo'.padStart(-1), 'foo', "No padding added if maxLength (first argument), negative, is less than the length of actual string");
36-
assert.areEqual('foo'.padStart(3), 'foo', "No padding added if maxLength (first argument) is equal to the length of actual string");
37-
assert.areEqual('foo'.padStart(4), ' foo', "String with one ' ' (SPACE) as pad is returned");
38-
assert.areEqual('foo'.padStart(10), ' foo', "String of length 10, with spaces filled as padding, is returned");
39-
assert.areEqual('foo'.padStart(10, ''), ' foo', "Empty fillString - string of length 10, with spaces filled as padding, is returned");
40-
assert.areEqual('foo'.padStart(10, undefined), ' foo', "'undefined' fillString - string of length 10, with spaces filled as padding, is returned");
41-
assert.areEqual('foo'.padStart(10, ' '), ' foo', "fillString as one space - string of length 10, with spaces filled as padding, is returned");
42-
assert.areEqual('foo'.padStart(4, '123'), '1foo', "String of length 4, with only one character from fillString added as a padding, is returned");
43-
assert.areEqual('foo'.padStart(10, '123'), '1231231foo', "String of length 10, with repeatedly adding characters from fillString to create enough padding, is returned");
44-
}
45-
},
46-
{
47-
name: "String.prototype.padEnd functionality",
48-
body: function () {
49-
assert.areEqual('foo'.padEnd(), 'foo', "No arguments to padEnd will not affect string");
50-
assert.areEqual('foo'.padEnd(1), 'foo', "No padding added if maxLength (first argument) is less than the length of actual string");
51-
assert.areEqual('foo'.padEnd(-1), 'foo', "No padding added if maxLength (first argument), negative, is less than the length of actual string");
52-
assert.areEqual('foo'.padEnd(3), 'foo', "No padding added if maxLength (first argument) is equal to the length of actual string");
53-
assert.areEqual('foo'.padEnd(4), 'foo ', "String with one ' ' (SPACE) as pad is returned");
54-
assert.areEqual('foo'.padEnd(10), 'foo ', "String of length 10, with spaces filled as padding, is returned");
55-
assert.areEqual('foo'.padEnd(10, ''), 'foo ', "Empty fillString - string of length 10, with spaces filled as padding, is returned");
56-
assert.areEqual('foo'.padEnd(10, undefined), 'foo ', "'undefined' fillString - string of length 10, with spaces filled as padding, is returned");
57-
assert.areEqual('foo'.padEnd(10, ' '), 'foo ', "fillString as one space - string of length 10, with spaces filled as padding, is returned");
58-
assert.areEqual('foo'.padEnd(4, '123'), 'foo1', "String of length 4, with only one character from fillString added as a padding, is returned");
59-
assert.areEqual('foo'.padEnd(10, '123'), 'foo1231231', "String of length 10, with repeatedly adding characters from fillString to create enough padding, is returned");
60-
}
61-
},
62-
{
63-
name: "String.prototype.padStart OOM scenario",
64-
body: function () {
65-
try {
66-
'foo'.padStart(2147483647);
67-
}
68-
catch(e) {
69-
assert.areEqual(e.message, "Out of memory", "validating out of memory for maxLength >= int_max");
70-
}
71-
}
72-
}
73-
];
74-
75-
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
7+
8+
var tests = [
9+
{
10+
name: "String.prototype.padStart/padEnd should exist and constructed properly",
11+
body: function () {
12+
assert.isTrue(String.prototype.hasOwnProperty('padStart'), "String.prototype should have a padStart method");
13+
assert.isTrue(String.prototype.hasOwnProperty('padEnd'), "String.prototype should have a padEnd method");
14+
assert.areEqual(1, String.prototype.padStart.length, "padStart method takes one argument");
15+
assert.areEqual(1, String.prototype.padEnd.length, "padEnd method takes one argument");
16+
assert.areEqual("padStart", String.prototype.padStart.name, "padStart.name is 'padStart'");
17+
assert.areEqual("padEnd", String.prototype.padEnd.name, "padEnd.name is 'padEnd'");
18+
19+
var descriptor = Object.getOwnPropertyDescriptor(String.prototype, 'padStart');
20+
assert.isTrue(descriptor.writable, "writable(padStart) must be true");
21+
assert.isFalse(descriptor.enumerable, "enumerable(padStart) must be false");
22+
assert.isTrue(descriptor.configurable, "configurable(padStart) must be true");
23+
24+
descriptor = Object.getOwnPropertyDescriptor(String.prototype, 'padEnd');
25+
assert.isTrue(descriptor.writable, "writable(padEnd) must be true");
26+
assert.isFalse(descriptor.enumerable, "enumerable(padEnd) must be false");
27+
assert.isTrue(descriptor.configurable, "configurable(padEnd) must be true");
28+
}
29+
},
30+
{
31+
name: "String.prototype.padStart functionality",
32+
body: function () {
33+
assert.areEqual('foo'.padStart(), 'foo', "No arguments to padStart will not affect string");
34+
assert.areEqual('foo'.padStart(1), 'foo', "No padding added if maxLength (first argument) is less than the length of actual string");
35+
assert.areEqual('foo'.padStart(-1), 'foo', "No padding added if maxLength (first argument), negative, is less than the length of actual string");
36+
assert.areEqual('foo'.padStart(3), 'foo', "No padding added if maxLength (first argument) is equal to the length of actual string");
37+
assert.areEqual('foo'.padStart(4), ' foo', "String with one ' ' (SPACE) as pad is returned");
38+
assert.areEqual('foo'.padStart(10), ' foo', "String of length 10, with spaces filled as padding, is returned");
39+
assert.areEqual('foo'.padStart(10, ''), 'foo', "No padding added if the fillString is empty string");
40+
assert.areEqual('foo'.padStart(10, undefined), ' foo', "'undefined' fillString - string of length 10, with spaces filled as padding, is returned");
41+
assert.areEqual('foo'.padStart(10, ' '), ' foo', "fillString as one space - string of length 10, with spaces filled as padding, is returned");
42+
assert.areEqual('foo'.padStart(4, '123'), '1foo', "String of length 4, with only one character from fillString added as a padding, is returned");
43+
assert.areEqual('foo'.padStart(10, '123'), '1231231foo', "String of length 10, with repeatedly adding characters from fillString to create enough padding, is returned");
44+
}
45+
},
46+
{
47+
name: "String.prototype.padEnd functionality",
48+
body: function () {
49+
assert.areEqual('foo'.padEnd(), 'foo', "No arguments to padEnd will not affect string");
50+
assert.areEqual('foo'.padEnd(1), 'foo', "No padding added if maxLength (first argument) is less than the length of actual string");
51+
assert.areEqual('foo'.padEnd(-1), 'foo', "No padding added if maxLength (first argument), negative, is less than the length of actual string");
52+
assert.areEqual('foo'.padEnd(3), 'foo', "No padding added if maxLength (first argument) is equal to the length of actual string");
53+
assert.areEqual('foo'.padEnd(4), 'foo ', "String with one ' ' (SPACE) as pad is returned");
54+
assert.areEqual('foo'.padEnd(10), 'foo ', "String of length 10, with spaces filled as padding, is returned");
55+
assert.areEqual('foo'.padEnd(10, ''), 'foo', "No padding added if the fillString is empty string");
56+
assert.areEqual('foo'.padEnd(10, undefined), 'foo ', "'undefined' fillString - string of length 10, with spaces filled as padding, is returned");
57+
assert.areEqual('foo'.padEnd(10, ' '), 'foo ', "fillString as one space - string of length 10, with spaces filled as padding, is returned");
58+
assert.areEqual('foo'.padEnd(4, '123'), 'foo1', "String of length 4, with only one character from fillString added as a padding, is returned");
59+
assert.areEqual('foo'.padEnd(10, '123'), 'foo1231231', "String of length 10, with repeatedly adding characters from fillString to create enough padding, is returned");
60+
}
61+
},
62+
{
63+
name: "String.prototype.padStart OOM scenario",
64+
body: function () {
65+
try {
66+
'foo'.padStart(2147483647);
67+
}
68+
catch(e) {
69+
assert.areEqual(e.message, "Out of memory", "validating out of memory for maxLength >= int_max");
70+
}
71+
}
72+
}
73+
];
74+
75+
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

0 commit comments

Comments
 (0)