-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversion to sequence<T> need not throw on a RegExp object #145
Comments
In general I find the way the Web IDL spec treats RegExp and Date objects specially rather strange... Maybe there is historical context I am missing. |
https://bugs.webkit.org/show_bug.cgi?id=160801 Reviewed by Darin Adler. Source/JavaScriptCore: Export functions used to iterate over iterable objects. * runtime/IteratorOperations.h: (JSC::forEachInIterable): Source/WebCore: Added the proper iterator support for sequence<T> with one caveat that we don't check for RegExp object per whatwg/webidl#145. See http://heycam.github.io/webidl/#es-sequence and http://heycam.github.io/webidl/#es-overloads Tests: bindings/scripts/test/TestOverloadedConstructorsWithSequence.idl * bindings/js/JSDOMBinding.cpp: (WebCore::hasIteratorMethod): Added. A helper function for checking whether a JSValue is iterable or not. * bindings/js/JSDOMBinding.h: (WebCore::NativeValueTraits<unsigned>::nativeValue): Removed the check for isNumber to match the spec'ed behavior at http://heycam.github.io/webidl/#es-unsigned-long which calls ToNumber first without checking whether the value is a number or not. (WebCore::toRefPtrNativeArray): Replaced isJSArray check by isObject check and throw a TypeError. Deployed forEachInIterable to support non-JSArray iterable objects. Also removed the function pointer from the third argument since we were always calling JSCT::toWrapped. (WebCore::toNativeArray): Ditto. * bindings/js/JSDOMConvert.h: (WebCore::Converter<Vector<T>>::convert): Removed the comment about toNativeArray not throwing when value is not an object. * bindings/scripts/CodeGeneratorJS.pm: (GenerateOverloadedFunctionOrConstructor): Removed the check for isJSArray for sequence<T> as an iterable object is not necessary a JSArray. (WillConvertUndefinedToDefaultParameterValue): Don't return 1 for all sequences since toNativeArray and toRefPtrNativeArray now throws on undefined due to isObject check. (JSValueToNative): Removed the third argument from toRefPtrNativeArray. * bindings/scripts/test/GObject/WebKitDOMTestOverloadedConstructorsWithSequence.cpp: Added. * bindings/scripts/test/GObject/WebKitDOMTestOverloadedConstructorsWithSequence.h: Added. * bindings/scripts/test/GObject/WebKitDOMTestOverloadedConstructorsWithSequencePrivate.h: Added. * bindings/scripts/test/JS/JSTestObj.cpp: (WebCore::jsTestObjPrototypeFunctionMethodWithOptionalSequenceIsEmpty): * bindings/scripts/test/JS/JSTestOverloadedConstructorsWithSequence.cpp: Added. * bindings/scripts/test/JS/JSTestOverloadedConstructorsWithSequence.h: Added. * bindings/scripts/test/JS/JSTestTypedefs.cpp: (WebCore::jsTestTypedefsPrototypeFunctionFunc): * bindings/scripts/test/TestOverloadedConstructorsWithSequence.idl: Added. LayoutTests: Added test cases for converting non-JSArray objects to sequence<T> for MutationObserver, FontFaceSet, and WebSocket. * fast/dom/MutationObserver/observe-exceptions-expected.txt: * fast/dom/MutationObserver/observe-exceptions.html: * fast/text/font-face-set-javascript-expected.txt: * fast/text/font-face-set-javascript.html: * http/tests/dom/window-open-about-webkit-org-and-access-document-expected.txt: Rebaselined due to js-test-pre.js change. * http/tests/resources/js-test-pre.js: Merged ToT from resources/js-test-pre.js. * http/tests/security/xssAuditor/block-does-not-leak-location-expected.txt: Rebaselined due to js-test-pre.js change. * http/tests/security/xssAuditor/block-does-not-leak-referrer-expected.txt: Ditto. * http/tests/websocket/tests/hybi/websocket-constructor-protocols-expected.txt: Added. * http/tests/websocket/tests/hybi/websocket-constructor-protocols.html: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@204500 268f45cc-cd09-0410-ab3c-d52691b4dbfc
The historical context is twofold:
I think we've already deviated that principle in item 2 when we made dictionary and sequence distinguishable while still allowing iterables to represent dictionaries. And I, personally, don't think it's a big deal to drop that principle entirely. That said, for the specific case of |
Fixes whatwg#148 Fixes whatwg#145
Fixes whatwg#148 Fixes whatwg#145
When an ECMAScript value V is converted to an IDL sequence value, we don't really need to throw a
TypeError
when V is a nativeRegExp
object.Ordinarily, a
RegExp
object wouldn't haveSymbol.iterator
defined. If it's defined, e.g.x = new RegExp; x[Symbol.iterator] = function* () { yield 1; }
, then we should be able to iterate over it.The text was updated successfully, but these errors were encountered: