Diff
Modified: trunk/LayoutTests/ChangeLog (208875 => 208876)
--- trunk/LayoutTests/ChangeLog 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/LayoutTests/ChangeLog 2016-11-18 05:07:23 UTC (rev 208876)
@@ -1,3 +1,14 @@
+2016-11-17 Sam Weinig <s...@webkit.org>
+
+ [WebIDL] Add support for ByteString
+ https://bugs.webkit.org/show_bug.cgi?id=164901
+
+ Reviewed by Darin Adler.
+
+ * js/dom/webidl-type-mapping-expected.txt:
+ * js/dom/webidl-type-mapping.html:
+ Add tests for ByteString using the new TypeConversions.testByteString attribute.
+
2016-11-17 Alex Christensen <achristen...@webkit.org>
Implement TextDecoder and TextEncoder
Modified: trunk/LayoutTests/js/dom/webidl-type-mapping-expected.txt (208875 => 208876)
--- trunk/LayoutTests/js/dom/webidl-type-mapping-expected.txt 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/LayoutTests/js/dom/webidl-type-mapping-expected.txt 2016-11-18 05:07:23 UTC (rev 208876)
@@ -1043,22 +1043,38 @@
converter.testString = "ð"
PASS converter.testUSVString is "ð"
PASS converter.testString is "ð"
+converter.testByteString = '!@#123ABCabc\x00\x80\xFF\r\n\t'
+PASS converter.testByteString is "!@#123ABCabc\u0000Âÿ\r\n\t"
+converter.testByteString = '\u00FF'
+PASS converter.testByteString is "ÿ"
+PASS converter.testByteString = '\u0100' threw exception TypeError: Type error.
+PASS converter.testByteString is "ÿ"
+PASS converter.testByteString = {toString: function() { throw Error(); }} threw exception Error.
+PASS converter.testByteString is "ÿ"
converter.testUSVString = true
converter.testString = true
+converter.testByteString = true
PASS converter.testUSVString is "true"
PASS converter.testString is "true"
+PASS converter.testByteString is "true"
converter.testUSVString = 123
converter.testString = 123
+converter.testByteString = 123
PASS converter.testUSVString is "123"
PASS converter.testString is "123"
+PASS converter.testByteString is "123"
converter.testUSVString = null
converter.testString = null
+converter.testByteString = null
PASS converter.testUSVString is "null"
PASS converter.testString is "null"
+PASS converter.testByteString is "null"
converter.testUSVString = undefined
converter.testString = undefined
+converter.testByteString = undefined
PASS converter.testUSVString is "undefined"
PASS converter.testString is "undefined"
+PASS converter.testByteString is "undefined"
converter.testUnion = 'hello'
PASS converter.testUnion is 'hello'
PASS typeof converter.testUnion is 'string'
Modified: trunk/LayoutTests/js/dom/webidl-type-mapping.html (208875 => 208876)
--- trunk/LayoutTests/js/dom/webidl-type-mapping.html 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/LayoutTests/js/dom/webidl-type-mapping.html 2016-11-18 05:07:23 UTC (rev 208876)
@@ -579,13 +579,26 @@
shouldBeEqualToString("converter.testUSVString", test.expected);
shouldBeEqualToString("converter.testString", test.input);
});
+
+evalAndLog("converter.testByteString = '!@#123ABCabc\\x00\\x80\\xFF\\r\\n\\t'");
+shouldBeEqualToString("converter.testByteString", "!@#123ABCabc\x00\x80\xFF\r\n\t");
+evalAndLog("converter.testByteString = '\\u00FF'");
+shouldBeEqualToString("converter.testByteString", "\u00FF");
+shouldThrow("converter.testByteString = '\\u0100'");
+shouldBeEqualToString("converter.testByteString", "\u00FF");
+shouldThrow("converter.testByteString = {toString: function() { throw Error(); }}");
+shouldBeEqualToString("converter.testByteString", "\u00FF");
+
["true", "123", "null", "undefined"].forEach(function(value) {
evalAndLog("converter.testUSVString = " + value);
evalAndLog("converter.testString = " + value);
+ evalAndLog("converter.testByteString = " + value);
shouldBeEqualToString("converter.testUSVString", value);
shouldBeEqualToString("converter.testString", value);
+ shouldBeEqualToString("converter.testByteString", value);
});
+
evalAndLog("converter.testUnion = 'hello'");
shouldBe("converter.testUnion", "'hello'");
shouldBe("typeof converter.testUnion", "'string'");
Modified: trunk/Source/WebCore/ChangeLog (208875 => 208876)
--- trunk/Source/WebCore/ChangeLog 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/Source/WebCore/ChangeLog 2016-11-18 05:07:23 UTC (rev 208876)
@@ -1,3 +1,44 @@
+2016-11-17 Sam Weinig <s...@webkit.org>
+
+ [WebIDL] Add support for ByteString
+ https://bugs.webkit.org/show_bug.cgi?id=164901
+
+ Reviewed by Darin Adler.
+
+ * bindings/generic/IDLTypes.h:
+ Make IDLByteString a IDLString.
+
+ * bindings/js/JSDOMBinding.cpp:
+ (WebCore::valueToByteString):
+ (WebCore::valueToUSVString):
+ * bindings/js/JSDOMBinding.h:
+ Add conversion function for ByteString and fix valueToUSVString to take an ExecState reference.
+
+ * bindings/js/JSDOMConvert.h:
+ (WebCore::Converter<IDLByteString>::convert):
+ (WebCore::JSConverter<IDLByteString>::convert):
+ Add conversion functions for ByteString, using valueToByteString.
+
+ (WebCore::Converter<IDLUSVString>::convert):
+ Update to pass the ExecState by reference.
+
+ * bindings/js/JSMessageEventCustom.cpp:
+ (WebCore::handleInitMessageEvent):
+ Update to pass the ExecState by reference.
+
+ * bindings/js/JSWorkerGlobalScopeCustom.cpp:
+ (WebCore::JSWorkerGlobalScope::importScripts):
+ Update to pass the ExecState by reference.
+
+ * bindings/scripts/CodeGenerator.pm:
+ Add ByteString as a string type.
+
+ * testing/TypeConversions.h:
+ (WebCore::TypeConversions::testByteString):
+ (WebCore::TypeConversions::setTestByteString):
+ * testing/TypeConversions.idl:
+ Add a testByteString attribute for testing.
+
2016-11-17 Ryosuke Niwa <rn...@webkit.org>
WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled should keep text replacement enabled
Modified: trunk/Source/WebCore/bindings/generic/IDLTypes.h (208875 => 208876)
--- trunk/Source/WebCore/bindings/generic/IDLTypes.h 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/Source/WebCore/bindings/generic/IDLTypes.h 2016-11-18 05:07:23 UTC (rev 208876)
@@ -86,7 +86,7 @@
template <typename U> static U&& extractValueFromNullable(U&& value) { return std::forward<U>(value); }
};
struct IDLDOMString : IDLString { };
-struct IDLByteString : IDLUnsupportedType { };
+struct IDLByteString : IDLString { };
struct IDLUSVString : IDLString { };
struct IDLObject : IDLUnsupportedType { };
Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp (208875 => 208876)
--- trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp 2016-11-18 05:07:23 UTC (rev 208876)
@@ -102,14 +102,30 @@
return false;
}
-String valueToUSVString(ExecState* exec, JSValue value)
+String valueToByteString(ExecState& state, JSValue value)
{
- VM& vm = exec->vm();
+ VM& vm = state.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
- String string = value.toWTFString(exec);
+ String string = value.toWTFString(&state);
RETURN_IF_EXCEPTION(scope, { });
+ if (!string.containsOnlyLatin1()) {
+ throwTypeError(&state, scope);
+ return { };
+ }
+
+ return string;
+}
+
+String valueToUSVString(ExecState& state, JSValue value)
+{
+ VM& vm = state.vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ String string = value.toWTFString(&state);
+ RETURN_IF_EXCEPTION(scope, { });
+
// Fast path for the case where there are no unpaired surrogates.
if (!hasUnpairedSurrogate(string))
return string;
Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.h (208875 => 208876)
--- trunk/Source/WebCore/bindings/js/JSDOMBinding.h 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.h 2016-11-18 05:07:23 UTC (rev 208876)
@@ -215,7 +215,8 @@
AtomicString propertyNameToAtomicString(JSC::PropertyName);
-WEBCORE_EXPORT String valueToUSVString(JSC::ExecState*, JSC::JSValue);
+WEBCORE_EXPORT String valueToByteString(JSC::ExecState&, JSC::JSValue);
+WEBCORE_EXPORT String valueToUSVString(JSC::ExecState&, JSC::JSValue);
int32_t finiteInt32Value(JSC::JSValue, JSC::ExecState*, bool& okay);
Modified: trunk/Source/WebCore/bindings/js/JSDOMConvert.h (208875 => 208876)
--- trunk/Source/WebCore/bindings/js/JSDOMConvert.h 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvert.h 2016-11-18 05:07:23 UTC (rev 208876)
@@ -709,10 +709,8 @@
template<> struct Converter<IDLDOMString> : DefaultConverter<IDLDOMString> {
static String convert(JSC::ExecState& state, JSC::JSValue value, StringConversionConfiguration configuration = StringConversionConfiguration::Normal)
{
- if (configuration == StringConversionConfiguration::TreatNullAsEmptyString) {
- if (value.isNull())
- return emptyString();
- }
+ if (configuration == StringConversionConfiguration::TreatNullAsEmptyString && value.isNull())
+ return emptyString();
return value.toWTFString(&state);
}
};
@@ -727,14 +725,31 @@
}
};
+template<> struct Converter<IDLByteString> : DefaultConverter<IDLByteString> {
+ static String convert(JSC::ExecState& state, JSC::JSValue value, StringConversionConfiguration configuration = StringConversionConfiguration::Normal)
+ {
+ if (configuration == StringConversionConfiguration::TreatNullAsEmptyString && value.isNull())
+ return emptyString();
+ return valueToByteString(state, value);
+ }
+};
+
+template<> struct JSConverter<IDLByteString> {
+ static constexpr bool needsState = true;
+ static constexpr bool needsGlobalObject = false;
+
+ static JSC::JSValue convert(JSC::ExecState& state, const String& value)
+ {
+ return JSC::jsStringWithCache(&state, value);
+ }
+};
+
template<> struct Converter<IDLUSVString> : DefaultConverter<IDLUSVString> {
static String convert(JSC::ExecState& state, JSC::JSValue value, StringConversionConfiguration configuration = StringConversionConfiguration::Normal)
{
- if (configuration == StringConversionConfiguration::TreatNullAsEmptyString) {
- if (value.isNull())
- return emptyString();
- }
- return valueToUSVString(&state, value);
+ if (configuration == StringConversionConfiguration::TreatNullAsEmptyString && value.isNull())
+ return emptyString();
+ return valueToUSVString(state, value);
}
};
Modified: trunk/Source/WebCore/bindings/js/JSMessageEventCustom.cpp (208875 => 208876)
--- trunk/Source/WebCore/bindings/js/JSMessageEventCustom.cpp 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/Source/WebCore/bindings/js/JSMessageEventCustom.cpp 2016-11-18 05:07:23 UTC (rev 208876)
@@ -119,7 +119,7 @@
JSValue dataArg = state.argument(3);
- const String originArg = valueToUSVString(&state, state.argument(4));
+ const String originArg = convert<IDLUSVString>(state, state.argument(4));
RETURN_IF_EXCEPTION(scope, JSValue());
const String lastEventIdArg = state.argument(5).toString(&state)->value(&state);
Modified: trunk/Source/WebCore/bindings/js/JSWorkerGlobalScopeCustom.cpp (208875 => 208876)
--- trunk/Source/WebCore/bindings/js/JSWorkerGlobalScopeCustom.cpp 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/Source/WebCore/bindings/js/JSWorkerGlobalScopeCustom.cpp 2016-11-18 05:07:23 UTC (rev 208876)
@@ -26,6 +26,7 @@
#include "config.h"
#include "JSWorkerGlobalScope.h"
+#include "JSDOMConvert.h"
#include "ScheduledAction.h"
#include "WorkerGlobalScope.h"
@@ -54,7 +55,7 @@
Vector<String> urls;
urls.reserveInitialCapacity(state.argumentCount());
for (unsigned i = 0; i < state.argumentCount(); ++i) {
- urls.uncheckedAppend(valueToUSVString(&state, state.uncheckedArgument(i)));
+ urls.uncheckedAppend(convert<IDLUSVString>(state, state.uncheckedArgument(i)));
RETURN_IF_EXCEPTION(scope, JSValue());
}
Modified: trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm (208875 => 208876)
--- trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm 2016-11-18 05:07:23 UTC (rev 208876)
@@ -65,6 +65,7 @@
);
my %stringTypeHash = (
+ "ByteString" => 1,
"DOMString" => 1,
"USVString" => 1,
);
Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestDOMJIT.cpp (208875 => 208876)
--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestDOMJIT.cpp 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestDOMJIT.cpp 2016-11-18 05:07:23 UTC (rev 208876)
@@ -26,7 +26,6 @@
#include "DOMJITIDLConvert.h"
#include "DOMJITIDLType.h"
#include "DOMJITIDLTypeFilter.h"
-#include "JSByteString.h"
#include "JSDOMBinding.h"
#include "JSDOMConstructor.h"
#include "JSDOMConvert.h"
@@ -671,7 +670,7 @@
UNUSED_PARAM(throwScope);
UNUSED_PARAM(state);
auto& impl = thisObject.wrapped();
- JSValue result = toJS<IDLByteString>(state, *thisObject.globalObject(), impl.byteStringAttr());
+ JSValue result = toJS<IDLByteString>(state, impl.byteStringAttr());
return result;
}
@@ -1130,7 +1129,7 @@
UNUSED_PARAM(throwScope);
UNUSED_PARAM(state);
auto& impl = thisObject.wrapped();
- JSValue result = toJS<IDLNullable<IDLByteString>>(state, *thisObject.globalObject(), impl.byteStringNullableAttr());
+ JSValue result = toJS<IDLNullable<IDLByteString>>(state, impl.byteStringNullableAttr());
return result;
}
Modified: trunk/Source/WebCore/testing/TypeConversions.h (208875 => 208876)
--- trunk/Source/WebCore/testing/TypeConversions.h 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/Source/WebCore/testing/TypeConversions.h 2016-11-18 05:07:23 UTC (rev 208876)
@@ -98,6 +98,8 @@
void setTestString(const String& string) { m_string = string; }
const String& testUSVString() const { return m_usvstring; }
void setTestUSVString(const String& usvstring) { m_usvstring = usvstring; }
+ const String& testByteString() const { return m_byteString; }
+ void setTestByteString(const String& byteString) { m_byteString = byteString; }
using TestUnion = Variant<String, int, bool, RefPtr<Node>, Vector<int>>;
const TestUnion& testUnion() const { return m_union; }
@@ -139,6 +141,7 @@
uint16_t m_UnsignedShort { 0 };
String m_string;
String m_usvstring;
+ String m_byteString;
TestUnion m_union;
int m_typeConversionsDictionaryLongValue { 0 };
Modified: trunk/Source/WebCore/testing/TypeConversions.idl (208875 => 208876)
--- trunk/Source/WebCore/testing/TypeConversions.idl 2016-11-18 04:57:50 UTC (rev 208875)
+++ trunk/Source/WebCore/testing/TypeConversions.idl 2016-11-18 05:07:23 UTC (rev 208876)
@@ -51,6 +51,7 @@
[EnforceRange] attribute unsigned short testEnforceRangeUnsignedShort;
attribute DOMString testString;
+ attribute ByteString testByteString;
attribute USVString testUSVString;
attribute (DOMString or long or boolean or Node or sequence<long>) testUnion;