haikuwebkit/JSTests/es6/String.prototype_methods_St...

120 lines
4.7 KiB
JavaScript
Raw Permalink Normal View History

function shouldBe(expected, actual, msg) {
if (msg === void 0)
msg = '';
else
msg = ' for ' + msg;
if (actual !== expected)
throw new Error('bad value' + msg + ': ' + actual + '. Expected ' + expected);
}
padStart/padEnd with Infinity produces unexpected result https://bugs.webkit.org/show_bug.cgi?id=159543 Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-07-07 Reviewed by Benjamin Poulain. Source/JavaScriptCore: * builtins/GlobalOperations.js: (globalPrivate.toLength): Fix style. * builtins/StringPrototype.js: (padStart): (padEnd): After all observable operations, and after empty string has been handled, throw an out of memory error if the resulting string would be greater than the maximum string size. * tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors-proxy.js: (shouldThrow): Deleted. * tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors.js: (shouldThrow): (testMeta): * tests/es6/String.prototype_methods_String.prototype.padEnd.js: (shouldThrow): (TestToLength): (TestMemoryLimits): (TestMeta): Deleted. * tests/es6/String.prototype_methods_String.prototype.padStart.js: (shouldThrow): (TestToLength): (TestMemoryLimits): Replace incorrect shouldThrow(..., errorType) with explicit shouldThrow(..., errorMessage). The old shouldThrow would incorrectly succeed if the expected error type was just "Error". Now we explicitly check the error message. LayoutTests: * js/script-tests/string-padend.js: Added. (thisObject.toString): (lengthObject.valueOf): (fillObject.toString): * js/script-tests/string-padstart.js: Added. (thisObject.toString): (lengthObject.valueOf): (fillObject.toString): * js/string-padend-expected.txt: Added. * js/string-padend.html: Added. * js/string-padstart-expected.txt: Added. * js/string-padstart.html: Added. Add some basic String.prototype.padStart/padEnd test coverage that is not just in the JavaScriptCore/tests/es6 directory. Canonical link: https://commits.webkit.org/177687@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202966 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-07-08 06:25:34 +00:00
function shouldThrow(func, errorMessage) {
var errorThrown = false;
var error = null;
try {
func();
} catch (e) {
padStart/padEnd with Infinity produces unexpected result https://bugs.webkit.org/show_bug.cgi?id=159543 Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-07-07 Reviewed by Benjamin Poulain. Source/JavaScriptCore: * builtins/GlobalOperations.js: (globalPrivate.toLength): Fix style. * builtins/StringPrototype.js: (padStart): (padEnd): After all observable operations, and after empty string has been handled, throw an out of memory error if the resulting string would be greater than the maximum string size. * tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors-proxy.js: (shouldThrow): Deleted. * tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors.js: (shouldThrow): (testMeta): * tests/es6/String.prototype_methods_String.prototype.padEnd.js: (shouldThrow): (TestToLength): (TestMemoryLimits): (TestMeta): Deleted. * tests/es6/String.prototype_methods_String.prototype.padStart.js: (shouldThrow): (TestToLength): (TestMemoryLimits): Replace incorrect shouldThrow(..., errorType) with explicit shouldThrow(..., errorMessage). The old shouldThrow would incorrectly succeed if the expected error type was just "Error". Now we explicitly check the error message. LayoutTests: * js/script-tests/string-padend.js: Added. (thisObject.toString): (lengthObject.valueOf): (fillObject.toString): * js/script-tests/string-padstart.js: Added. (thisObject.toString): (lengthObject.valueOf): (fillObject.toString): * js/string-padend-expected.txt: Added. * js/string-padend.html: Added. * js/string-padstart-expected.txt: Added. * js/string-padstart.html: Added. Add some basic String.prototype.padStart/padEnd test coverage that is not just in the JavaScriptCore/tests/es6 directory. Canonical link: https://commits.webkit.org/177687@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202966 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-07-08 06:25:34 +00:00
errorThrown = true;
error = e;
}
padStart/padEnd with Infinity produces unexpected result https://bugs.webkit.org/show_bug.cgi?id=159543 Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-07-07 Reviewed by Benjamin Poulain. Source/JavaScriptCore: * builtins/GlobalOperations.js: (globalPrivate.toLength): Fix style. * builtins/StringPrototype.js: (padStart): (padEnd): After all observable operations, and after empty string has been handled, throw an out of memory error if the resulting string would be greater than the maximum string size. * tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors-proxy.js: (shouldThrow): Deleted. * tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors.js: (shouldThrow): (testMeta): * tests/es6/String.prototype_methods_String.prototype.padEnd.js: (shouldThrow): (TestToLength): (TestMemoryLimits): (TestMeta): Deleted. * tests/es6/String.prototype_methods_String.prototype.padStart.js: (shouldThrow): (TestToLength): (TestMemoryLimits): Replace incorrect shouldThrow(..., errorType) with explicit shouldThrow(..., errorMessage). The old shouldThrow would incorrectly succeed if the expected error type was just "Error". Now we explicitly check the error message. LayoutTests: * js/script-tests/string-padend.js: Added. (thisObject.toString): (lengthObject.valueOf): (fillObject.toString): * js/script-tests/string-padstart.js: Added. (thisObject.toString): (lengthObject.valueOf): (fillObject.toString): * js/string-padend-expected.txt: Added. * js/string-padend.html: Added. * js/string-padstart-expected.txt: Added. * js/string-padstart.html: Added. Add some basic String.prototype.padStart/padEnd test coverage that is not just in the JavaScriptCore/tests/es6 directory. Canonical link: https://commits.webkit.org/177687@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202966 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-07-08 06:25:34 +00:00
if (!errorThrown)
throw new Error('not thrown');
if (String(error) !== errorMessage)
throw new Error(`bad error: ${String(error)}`);
}
(function TestMeta() {
shouldBe(1, String.prototype.padEnd.length);
shouldBe("function", typeof String.prototype.padStart);
shouldBe(Object.getPrototypeOf(Function), Object.getPrototypeOf(String.prototype.padStart));
shouldBe("padStart", String.prototype.padStart.name);
var descriptor = Object.getOwnPropertyDescriptor(String.prototype, "padStart");
shouldBe(undefined, descriptor.get);
shouldBe(undefined, descriptor.set);
shouldBe(true, descriptor.configurable);
shouldBe(false, descriptor.enumerable);
shouldBe(true, descriptor.writable);
shouldBe(String.prototype.padStart, descriptor.value);
padStart/padEnd with Infinity produces unexpected result https://bugs.webkit.org/show_bug.cgi?id=159543 Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-07-07 Reviewed by Benjamin Poulain. Source/JavaScriptCore: * builtins/GlobalOperations.js: (globalPrivate.toLength): Fix style. * builtins/StringPrototype.js: (padStart): (padEnd): After all observable operations, and after empty string has been handled, throw an out of memory error if the resulting string would be greater than the maximum string size. * tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors-proxy.js: (shouldThrow): Deleted. * tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors.js: (shouldThrow): (testMeta): * tests/es6/String.prototype_methods_String.prototype.padEnd.js: (shouldThrow): (TestToLength): (TestMemoryLimits): (TestMeta): Deleted. * tests/es6/String.prototype_methods_String.prototype.padStart.js: (shouldThrow): (TestToLength): (TestMemoryLimits): Replace incorrect shouldThrow(..., errorType) with explicit shouldThrow(..., errorMessage). The old shouldThrow would incorrectly succeed if the expected error type was just "Error". Now we explicitly check the error message. LayoutTests: * js/script-tests/string-padend.js: Added. (thisObject.toString): (lengthObject.valueOf): (fillObject.toString): * js/script-tests/string-padstart.js: Added. (thisObject.toString): (lengthObject.valueOf): (fillObject.toString): * js/string-padend-expected.txt: Added. * js/string-padend.html: Added. * js/string-padstart-expected.txt: Added. * js/string-padstart.html: Added. Add some basic String.prototype.padStart/padEnd test coverage that is not just in the JavaScriptCore/tests/es6 directory. Canonical link: https://commits.webkit.org/177687@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202966 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-07-08 06:25:34 +00:00
shouldThrow(() => new Function(`${String.prototype.padStart}`), "SyntaxError: Unexpected identifier 'code'. Expected either a closing ']' or a ',' following an array element.");
})();
(function TestRequireObjectCoercible() {
var padStart = String.prototype.padStart;
Make builtin TypeErrors consistent https://bugs.webkit.org/show_bug.cgi?id=159899 Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-07-18 Reviewed by Keith Miller. Source/JavaScriptCore: Converge on the single TypeError for non-coercible this objects in builtins. Also update some other style to be more consistent with-in builtins. * builtins/ArrayIteratorPrototype.js: (next): * builtins/ArrayPrototype.js: (values): (keys): (entries): (reduce): (reduceRight): (every): (forEach): (filter): (map): (some): (fill): (find): (findIndex): (includes): (sort): (concatSlowPath): (copyWithin): * builtins/StringPrototype.js: (match): (repeat): (padStart): (padEnd): (intrinsic.StringPrototypeReplaceIntrinsic.replace): (localeCompare): (search): (split): * tests/es6/String.prototype_methods_String.prototype.padEnd.js: * tests/es6/String.prototype_methods_String.prototype.padStart.js: * tests/stress/array-iterators-next-error-messages.js: (catch): * tests/stress/array-iterators-next-with-call.js: * tests/stress/regexp-match.js: (shouldThrow): * tests/stress/regexp-search.js: (shouldThrow): LayoutTests: * js/array-find-expected.txt: * js/array-findIndex-expected.txt: * js/array-includes-expected.txt: * js/dom/array-prototype-properties-expected.txt: * js/dom/script-tests/string-prototype-properties.js: * js/dom/string-prototype-properties-expected.txt: * js/script-tests/array-find.js: * js/script-tests/array-findIndex.js: * js/script-tests/string-localeCompare.js: * js/string-localeCompare-expected.txt: * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.10_String.prototype.match/S15.5.4.10_A1_T3-expected.txt: * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.11_String.prototype.replace/S15.5.4.11_A1_T3-expected.txt: * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.12_String.prototype.search/S15.5.4.12_A1_T3-expected.txt: * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.14_String.prototype.split/S15.5.4.14_A1_T3-expected.txt: Canonical link: https://commits.webkit.org/178077@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@203393 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-07-19 02:45:35 +00:00
shouldThrow(() => padStart.call(null, 4, "test"), "TypeError: String.prototype.padStart requires that |this| not be null or undefined");
shouldThrow(() => padStart.call(undefined, 4, "test"), "TypeError: String.prototype.padStart requires that |this| not be null or undefined");
shouldBe(" 123", padStart.call({
__proto__: null,
valueOf() { return 123; }
}, 6, " "));
var proxy = new Proxy({}, {
get(t, name) {
if (name === Symbol.toPrimitive || name === "toString") return;
if (name === "valueOf") return () => 6.7;
throw new Error("unreachable code");
}
});
shouldBe(" 6.7", padStart.call(proxy, 6, " "));
proxy = new Proxy({}, {
get(t, name) {
if (name === Symbol.toPrimitive || name === "valueOf") return;
if (name === "toString") return () => 6.7;
throw new Error("unreachable code");
}
});
shouldBe(" 6.7", padStart.call(proxy, 6, " "));
})();
(function TestToLength() {
padStart/padEnd with Infinity produces unexpected result https://bugs.webkit.org/show_bug.cgi?id=159543 Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-07-07 Reviewed by Benjamin Poulain. Source/JavaScriptCore: * builtins/GlobalOperations.js: (globalPrivate.toLength): Fix style. * builtins/StringPrototype.js: (padStart): (padEnd): After all observable operations, and after empty string has been handled, throw an out of memory error if the resulting string would be greater than the maximum string size. * tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors-proxy.js: (shouldThrow): Deleted. * tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors.js: (shouldThrow): (testMeta): * tests/es6/String.prototype_methods_String.prototype.padEnd.js: (shouldThrow): (TestToLength): (TestMemoryLimits): (TestMeta): Deleted. * tests/es6/String.prototype_methods_String.prototype.padStart.js: (shouldThrow): (TestToLength): (TestMemoryLimits): Replace incorrect shouldThrow(..., errorType) with explicit shouldThrow(..., errorMessage). The old shouldThrow would incorrectly succeed if the expected error type was just "Error". Now we explicitly check the error message. LayoutTests: * js/script-tests/string-padend.js: Added. (thisObject.toString): (lengthObject.valueOf): (fillObject.toString): * js/script-tests/string-padstart.js: Added. (thisObject.toString): (lengthObject.valueOf): (fillObject.toString): * js/string-padend-expected.txt: Added. * js/string-padend.html: Added. * js/string-padstart-expected.txt: Added. * js/string-padstart.html: Added. Add some basic String.prototype.padStart/padEnd test coverage that is not just in the JavaScriptCore/tests/es6 directory. Canonical link: https://commits.webkit.org/177687@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202966 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-07-08 06:25:34 +00:00
shouldThrow(() => "123".padStart(Symbol("16")), "TypeError: Cannot convert a symbol to a number");
shouldBe("123", "123".padStart(-1));
shouldBe("123", "123".padStart({ toString() { return -1; } }));
shouldBe("123", "123".padStart(-0));
shouldBe("123", "123".padStart({ toString() { return -0; } }));
shouldBe("123", "123".padStart(+0));
shouldBe("123", "123".padStart({ toString() { return +0; } }));
shouldBe("123", "123".padStart(NaN));
shouldBe("123", "123".padStart({ toString() { return NaN; } }));
})();
(function TestFillerToString() {
shouldBe(" .", ".".padStart(10));
shouldBe(" .", ".".padStart(10, undefined));
shouldBe("XXXXXXXXX.", ".".padStart(10, { toString() { return "X"; } }));
shouldBe("111111111.", ".".padStart(10, { toString: undefined, valueOf() { return 1; } }));
shouldBe("nullnulln.", ".".padStart(10, null));
})();
(function TestFillerEmptyString() {
shouldBe(".", ".".padStart(10000, ""));
shouldBe(".", ".".padStart(10000, { toString() { return ""; } }));
shouldBe(".", ".".padStart(10000, { toString: undefined, valueOf() { return ""; } }));
})();
(function TestSingleCharacterFiller() {
shouldBe("!!!!!!!!!.", ".".padStart(10, "!"));
shouldBe("!!!!!!!!!.", ".".padStart(10, { toString() { return "!"; } }));
shouldBe("!!!!!!!!!.", ".".padStart(10, "" + "!" + ""));
shouldBe("!!!!!!!!!.", ".".padStart(10, { toString() { return "" + "!" + ""; } }));
})();
(function TestMemoryLimits() {
[JSC] Make OutOfMemory error as instance of RangeError https://bugs.webkit.org/show_bug.cgi?id=211952 Reviewed by Mark Lam. JSTests: * ChakraCore/test/Error/outofmem.baseline-jsc: * es6/String.prototype_methods_String.prototype.padEnd.js: (TestMemoryLimits): * es6/String.prototype_methods_String.prototype.padStart.js: (TestMemoryLimits): * slowMicrobenchmarks/function-constructor-with-huge-strings.js: * stress/array-join-on-strings-need-overflow-checks.js: * stress/big-wasm-memory-grow-no-max.js: (test): * stress/big-wasm-memory-grow.js: (test): * stress/big-wasm-memory.js: (test): * stress/bigint-exponential-oom.js: (shouldThrow): * stress/bigint-int32-min-shift.js: (shouldThrow): * stress/check-symbol-description-oom.js: * stress/constructFunctionSkippingEvalEnabledCheck-should-throw-out-of-memory-error.js: * stress/intl-canonicalize-locale-list-error-oom.js: (shouldThrow): * stress/joined-strings-should-not-exceed-max-string-length.js: * stress/js-fixed-array-out-of-memory.js: (test): * stress/json-stringified-overflow-2.js: (catch): * stress/json-stringified-overflow.js: (catch): * stress/json-stringify-string-builder-overflow.js: * stress/missing-exception-check-in-JSValue-toWTFStringSlowCase.js: * stress/missing-exception-check-in-array-prototype-fastJoin.js: * stress/missing-exception-check-in-canonicalizeLocaleList.js: * stress/missing-exception-check-in-json-stringifier-gap.js: * stress/missing-exception-check-in-string-compare.js: * stress/missing-exception-check-in-string-greater-than-compare.js: * stress/missing-exception-check-in-string-greater-than-or-equal-compare.js: * stress/missing-exception-check-in-string-lastIndexOf.js: * stress/missing-exception-check-in-string-less-than-compare.js: * stress/missing-exception-check-in-string-less-than-or-equal-compare.js: * stress/missing-exception-check-in-string-toLower.js: * stress/missing-exception-check-in-string-toUpper.js: * stress/new_array_with_spread-should-cap-array-size-to-MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.js: * stress/out-of-memory-while-constructing-BytecodeGenerator.js: * stress/regexp-prototype-exec-on-too-long-rope.js: * stress/regexp-prototype-match-on-too-long-rope.js: * stress/regexp-prototype-test-on-too-long-rope.js: * stress/regress-169783.js: (doTest): * stress/regress-178385.js: * stress/regress-178386.js: * stress/regress-185888.js: * stress/regress-189132.js: * stress/regress-190187.js: * stress/regress-191563.js: * stress/scoped-arguments-table-should-be-tolerant-for-oom.js: (i.canThrow): * stress/string-16bit-repeat-overflow.js: * stress/string-overflow-createError-builder.js: * stress/string-overflow-createError-fit.js: * stress/string-overflow-createError.js: * stress/string-prototype-charCodeAt-on-too-long-rope.js: * stress/string-prototype-replace-should-throw-out-of-memory-error-when-using-too-much-memory.js: * stress/switch-string-oom.js: (testLowerTiers): (testFTL): * stress/test-exception-assert-in-ExceptionHelpers-createError.js: * stress/test-out-of-memory.js: * stress/typed-array-subarray-can-throw-oom-error.js: (get bar): * wasm/regress/wasm-memory-requested-more-than-MAX_ARRAY_BUFFER_SIZE-2.js: * wasm/regress/wasm-memory-requested-more-than-MAX_ARRAY_BUFFER_SIZE.js: Source/JavaScriptCore: The spec sometimes requires "check parameters and throw RangeError" before allocating an object. But we are just allocating an object and throwing an out-of-memory error since wrong parameter will cause out-of-memory. If out-of-memory error is RangeError, then we can keep our current behavior while we can make us spec compliant. And note that out-of-memory error is RangeError in SpiderMonkey and V8. This patch makes out-of-memory error as RangeError instead of Error. We also fix @throwOutOfMemoryError in builtin code: the previous thrown errors are not marked as out-of-memory error. * bytecode/BytecodeList.rb: * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitThrowStaticError): (JSC::BytecodeGenerator::emitThrowReferenceError): (JSC::BytecodeGenerator::emitThrowTypeError): (JSC::BytecodeGenerator::emitThrowRangeError): (JSC::BytecodeGenerator::emitThrowOutOfMemoryError): * bytecompiler/BytecodeGenerator.h: * bytecompiler/NodesCodegen.cpp: (JSC::RegExpNode::emitBytecode): (JSC::BytecodeIntrinsicNode::emit_intrinsic_throwTypeError): (JSC::BytecodeIntrinsicNode::emit_intrinsic_throwRangeError): * dfg/DFGOperations.cpp: * runtime/CommonSlowPaths.cpp: (JSC::SLOW_PATH_DECL): * runtime/Error.cpp: (JSC::createError): (JSC::createOutOfMemoryError): * runtime/Error.h: * runtime/ErrorType.cpp: (JSC::errorTypeName): (WTF::printInternal): * runtime/ErrorType.h: We introduced ErrorTypeWithExtension separately from ErrorType to keep ErrorType one-on-one to spec-specified error types. LayoutTests: * inspector/debugger/no-pause-out-of-memory-exception-expected.txt: * js/array-join-expected.txt: * js/dom/concat-large-strings-crash-expected.txt: * js/dom/concat-large-strings-crash2-expected.txt: * js/dom/script-tests/string-replacement-outofmemory.js: * js/dom/string-concatenate-outofmemory-expected.txt: * js/dom/string-replacement-outofmemory-expected.txt: * js/large-expressions-expected.txt: * js/resources/string-concatenate-outofmemory.js: * js/script-tests/array-join.js: * js/script-tests/stack-overflow-regexp.js: (shouldThrow.recursiveCall): (shouldThrow): * js/script-tests/string-padend.js: * js/script-tests/string-padstart.js: * js/script-tests/string-repeat.js: * js/script-tests/stringimpl-to-jsstring-on-large-strings-1.js: * js/stack-overflow-regexp-expected.txt: * js/string-padend-expected.txt: * js/string-padstart-expected.txt: * js/string-repeat-expected.txt: * js/stringimpl-to-jsstring-on-large-strings-1-expected.txt: Canonical link: https://commits.webkit.org/224872@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-16 08:24:22 +00:00
shouldThrow(() => ".".padStart(0x80000000, "o"), "RangeError: Out of memory");
shouldThrow(() => ".".padStart({ valueOf() { return 0x80000000; } }, "o"), "RangeError: Out of memory");
shouldThrow(() => ".".padStart("0x80000000", "o"), "RangeError: Out of memory");
})();
(function TestFillerRepetition() {
for (var i = 2000; i > 0; --i) {
var expected = "xoxo".repeat(i / 4).slice(0, i - 3) + "123";
var actual = "123".padStart(i, "xoxo");
shouldBe(expected, actual);
shouldBe(i > "123".length ? i : 3, actual.length);
actual = "123".padStart(i, "xo" + "" + "xo");
shouldBe(expected, actual);
shouldBe(i > "123".length ? i : 3, actual.length);
}
})();