WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-144160-20150425224842.patch (text/plain), 6.48 KB, created by
Yusuke Suzuki
on 2015-04-25 06:49:49 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Yusuke Suzuki
Created:
2015-04-25 06:49:49 PDT
Size:
6.48 KB
patch
obsolete
>Subversion Revision: 183309 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index 2b27adb3dc382bcad17f5983c118c39fbb1a45cc..99723b075592d0d28da43401a3759cf4b3109876 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,26 @@ >+2015-04-25 Yusuke Suzuki <utatane.tea@gmail.com> >+ >+ [ES6] Implement String.fromCodePoint >+ https://bugs.webkit.org/show_bug.cgi?id=144160 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch implements String.fromCodePoint. >+ It accepts multiple code points and generates a string that consists of given code points. >+ The range [0x0000 - 0x10FFFF] is valid for code points. >+ If the given value is out of range, throw a range error. >+ >+ When a 0xFFFF <= valid code point is given, >+ String.fromCodePoint generates a string that contains surrogate pairs. >+ >+ * runtime/StringConstructor.cpp: >+ (JSC::stringFromCodePoint): >+ (JSC::constructWithStringConstructor): >+ * tests/stress/string-from-code-points.js: Added. >+ (shouldBe): >+ (shouldThrow): >+ (toCodePoints): >+ > 2015-04-24 Commit Queue <commit-queue@webkit.org> > > Unreviewed, rolling out r183288. >diff --git a/Source/JavaScriptCore/runtime/StringConstructor.cpp b/Source/JavaScriptCore/runtime/StringConstructor.cpp >index a39973e1c5541e9034378a19d8efc89c608f5317..dc21523276984ee2d05e7e7179ed91ff036e3b31 100644 >--- a/Source/JavaScriptCore/runtime/StringConstructor.cpp >+++ b/Source/JavaScriptCore/runtime/StringConstructor.cpp >@@ -21,6 +21,7 @@ > #include "config.h" > #include "StringConstructor.h" > >+#include "Error.h" > #include "Executable.h" > #include "JITCode.h" > #include "JSFunction.h" >@@ -31,6 +32,7 @@ > namespace JSC { > > static EncodedJSValue JSC_HOST_CALL stringFromCharCode(ExecState*); >+static EncodedJSValue JSC_HOST_CALL stringFromCodePoint(ExecState*); > > } > >@@ -43,6 +45,7 @@ > /* Source for StringConstructor.lut.h > @begin stringConstructorTable > fromCharCode stringFromCharCode DontEnum|Function 1 >+ fromCodePoint stringFromCodePoint DontEnum|Function 1 > @end > */ > >@@ -89,6 +92,33 @@ JSCell* JSC_HOST_CALL stringFromCharCode(ExecState* exec, int32_t arg) > return jsSingleCharacterString(exec, arg); > } > >+static EncodedJSValue JSC_HOST_CALL stringFromCodePoint(ExecState* exec) >+{ >+ unsigned length = exec->argumentCount(); >+ StringBuilder builder; >+ builder.reserveCapacity(length); >+ >+ for (unsigned i = 0; i < length; ++i) { >+ double codePointAsDouble = exec->uncheckedArgument(i).toNumber(exec); >+ if (exec->hadException()) >+ return JSValue::encode(jsUndefined()); >+ >+ uint32_t codePoint = static_cast<UChar32>(codePointAsDouble); >+ >+ if (codePoint != codePointAsDouble || codePoint > 0x10FFFF) >+ return throwVMError(exec, createRangeError(exec, ASCIILiteral("Arguments contain a value that is out of range of code points"))); >+ >+ if (U_IS_BMP(codePoint)) >+ builder.append(static_cast<UChar>(codePoint)); >+ else { >+ builder.append(U16_LEAD(codePoint)); >+ builder.append(U16_TRAIL(codePoint)); >+ } >+ } >+ >+ return JSValue::encode(jsString(exec, builder.toString())); >+} >+ > static EncodedJSValue JSC_HOST_CALL constructWithStringConstructor(ExecState* exec) > { > JSGlobalObject* globalObject = asInternalFunction(exec->callee())->globalObject(); >@@ -96,7 +126,7 @@ static EncodedJSValue JSC_HOST_CALL constructWithStringConstructor(ExecState* ex > > if (!exec->argumentCount()) > return JSValue::encode(StringObject::create(vm, globalObject->stringObjectStructure())); >- >+ > return JSValue::encode(StringObject::create(vm, globalObject->stringObjectStructure(), exec->uncheckedArgument(0).toString(exec))); > } > >diff --git a/Source/JavaScriptCore/tests/stress/string-from-code-points.js b/Source/JavaScriptCore/tests/stress/string-from-code-points.js >new file mode 100644 >index 0000000000000000000000000000000000000000..9e413f2badcf75a4ea46d8ac29eb4d72061d72a5 >--- /dev/null >+++ b/Source/JavaScriptCore/tests/stress/string-from-code-points.js >@@ -0,0 +1,108 @@ >+function shouldBe(actual, expected) { >+ if (actual !== expected) >+ throw new Error("bad value: " + String(actual)); >+} >+ >+function shouldThrow(func, message) { >+ var error = null; >+ try { >+ func(); >+ } catch (e) { >+ error = e; >+ } >+ if (!error) >+ throw new Error("not thrown."); >+ if (String(error) !== message) >+ throw new Error("bad error: " + String(error)); >+} >+ >+function toCodePoints(string) { >+ var result = []; >+ for (var codePoint of string) { >+ result.push(codePoint.codePointAt(0)); >+ } >+ return result; >+} >+ >+shouldBe(String.fromCodePoint(), ""); >+shouldBe(String.fromCodePoint(0), "\0"); >+shouldBe(String.fromCodePoint(0, 0), "\0\0"); >+ >+var tests = [ >+ "", >+ "Hello", >+ "Cocoa", >+ "Cappuccino Cocoa", >+ "æ¥æ¬èª", >+ "ãã«ããã¤ã", >+ "åéå±", >+ "ð ®·éå®¶", // Contain a surrogate pair. >+]; >+ >+for (var test of tests) { >+ shouldBe(String.fromCodePoint.apply(String, toCodePoints(test)), test); >+} >+ >+var numberTests = [ >+ [ 0x10FFFF, "\uDBFF\uDFFF" ], >+ [ 0x10FFFE, "\uDBFF\uDFFE" ], >+ [ 0xFFFF, "\uFFFF" ], >+ [ 0x10000, "\uD800\uDC00" ], >+ [ 0x10001, "\uD800\uDC01" ], >+ [ -0.0, "\u0000" ], >+]; >+ >+for (var test of numberTests) { >+ shouldBe(String.fromCodePoint(test[0]), test[1]); >+} >+ >+var invalidTests = [ >+ -1, >+ 1.2, >+ 1.5, >+ 30.01, >+ -11.0, >+ NaN, >+ Number.Infinity, >+ -Number.Infinity, >+ 0x10FFFF + 1, >+ "Hello", >+ undefined, >+ {}, >+]; >+ >+for (var test of invalidTests) { >+ shouldThrow(function () { >+ String.fromCodePoint(test); >+ }, "RangeError: Arguments contain a value that is out of range of code points"); >+} >+ >+// toNumber causes errors. >+shouldThrow(function () { >+ String.fromCodePoint(Symbol.iterator); >+}, "TypeError: Type error") >+ >+var toNumberObject = { >+ valueOf() { >+ throw new Error("valueOf is called"); >+ } >+}; >+ >+shouldThrow(function () { >+ String.fromCodePoint(toNumberObject); >+}, "Error: valueOf is called") >+ >+shouldThrow(function () { >+ String.fromCodePoint(Symbol.iterator, toNumberObject); >+}, "TypeError: Type error") >+ >+var convertAndPassTests = [ >+ [ null, "\0" ], >+ [ [], "\0" ], >+ [ "0x41", "A" ], >+ [ "", "\0" ], >+]; >+ >+for (var test of convertAndPassTests) { >+ shouldBe(String.fromCodePoint(test[0]), test[1]); >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 144160
:
251579
|
251581
|
251582
|
251632
|
251633
|
251635
|
251638
|
251639