Title: [186323] trunk/Source
Revision
186323
Author
[email protected]
Date
2015-07-06 02:02:29 -0700 (Mon, 06 Jul 2015)

Log Message

[Streams API] Remove ReadableStream custom constructor
https://bugs.webkit.org/show_bug.cgi?id=146547

Reviewed by Darin Adler.

Source/_javascript_Core:

Adding helper function to throw range errors.

* runtime/Error.h:
(JSC::throwRangeError):
(JSC::throwVMRangeError):

Source/WebCore:

Removed custom binding.
Made use of Dictionary in lieu of JSObject to reduce readable stream constructor parameter parsing.
Added support for passing ExecState to construtor within binding generator.

No change in behavior.

* Modules/streams/ReadableStream.cpp:
(WebCore::ReadableStream::create):
* Modules/streams/ReadableStream.h:
(WebCore::ReadableStream::create):
* Modules/streams/ReadableStream.idl:
* bindings/js/JSDictionary.cpp:
(WebCore::JSDictionary::convertValue):
* bindings/js/JSDictionary.h:
* bindings/js/JSReadableStreamCustom.cpp:
* bindings/js/ReadableJSStream.cpp:
(WebCore::ReadableJSStream::create):
(WebCore::ReadableJSStream::ReadableJSStream):
* bindings/js/ReadableJSStream.h:
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateConstructorDefinition):
* bindings/scripts/IDLAttributes.txt:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (186322 => 186323)


--- trunk/Source/_javascript_Core/ChangeLog	2015-07-06 09:01:02 UTC (rev 186322)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-07-06 09:02:29 UTC (rev 186323)
@@ -1,3 +1,16 @@
+2015-07-06  Youenn Fablet  <[email protected]>
+
+        [Streams API] Remove ReadableStream custom constructor
+        https://bugs.webkit.org/show_bug.cgi?id=146547
+
+        Reviewed by Darin Adler.
+
+        Adding helper function to throw range errors.
+
+        * runtime/Error.h:
+        (JSC::throwRangeError):
+        (JSC::throwVMRangeError):
+
 2015-07-05  Yusuke Suzuki  <[email protected]>
 
         [ES6] Implement the latest Promise spec in JS

Modified: trunk/Source/_javascript_Core/runtime/Error.h (186322 => 186323)


--- trunk/Source/_javascript_Core/runtime/Error.h	2015-07-06 09:01:02 UTC (rev 186322)
+++ trunk/Source/_javascript_Core/runtime/Error.h	2015-07-06 09:02:29 UTC (rev 186323)
@@ -74,12 +74,14 @@
 // Convenience wrappers, create an throw an exception with a default message.
 JS_EXPORT_PRIVATE JSObject* throwTypeError(ExecState*);
 JS_EXPORT_PRIVATE JSObject* throwSyntaxError(ExecState*);
+inline JSObject* throwRangeError(ExecState* state, const String& errorMessage) { return state->vm().throwException(state, createRangeError(state, errorMessage)); }
 
 // Convenience wrappers, wrap result as an EncodedJSValue.
 inline void throwVMError(ExecState* exec, Exception* exception) { exec->vm().throwException(exec, exception); }
 inline EncodedJSValue throwVMError(ExecState* exec, JSValue error) { return JSValue::encode(exec->vm().throwException(exec, error)); }
 inline EncodedJSValue throwVMTypeError(ExecState* exec) { return JSValue::encode(throwTypeError(exec)); }
 inline EncodedJSValue throwVMTypeError(ExecState* exec, const String& errorMessage) { return JSValue::encode(throwTypeError(exec, errorMessage)); }
+inline EncodedJSValue throwVMRangeError(ExecState* state, const String& errorMessage) { return JSValue::encode(throwRangeError(state, errorMessage)); }
 
 class StrictModeTypeErrorFunction : public InternalFunction {
 private:

Modified: trunk/Source/WebCore/ChangeLog (186322 => 186323)


--- trunk/Source/WebCore/ChangeLog	2015-07-06 09:01:02 UTC (rev 186322)
+++ trunk/Source/WebCore/ChangeLog	2015-07-06 09:02:29 UTC (rev 186323)
@@ -1,5 +1,35 @@
 2015-07-06  Youenn Fablet  <[email protected]>
 
+        [Streams API] Remove ReadableStream custom constructor
+        https://bugs.webkit.org/show_bug.cgi?id=146547
+
+        Reviewed by Darin Adler.
+
+        Removed custom binding.
+        Made use of Dictionary in lieu of JSObject to reduce readable stream constructor parameter parsing.
+        Added support for passing ExecState to construtor within binding generator.
+
+        No change in behavior.
+
+        * Modules/streams/ReadableStream.cpp:
+        (WebCore::ReadableStream::create):
+        * Modules/streams/ReadableStream.h:
+        (WebCore::ReadableStream::create):
+        * Modules/streams/ReadableStream.idl:
+        * bindings/js/JSDictionary.cpp:
+        (WebCore::JSDictionary::convertValue):
+        * bindings/js/JSDictionary.h:
+        * bindings/js/JSReadableStreamCustom.cpp:
+        * bindings/js/ReadableJSStream.cpp:
+        (WebCore::ReadableJSStream::create):
+        (WebCore::ReadableJSStream::ReadableJSStream):
+        * bindings/js/ReadableJSStream.h:
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateConstructorDefinition):
+        * bindings/scripts/IDLAttributes.txt:
+
+2015-07-06  Youenn Fablet  <[email protected]>
+
         Promise-returning functions should reject promises if the callee is not of the expected type
         https://bugs.webkit.org/show_bug.cgi?id=146585
 

Modified: trunk/Source/WebCore/Modules/streams/ReadableStream.cpp (186322 => 186323)


--- trunk/Source/WebCore/Modules/streams/ReadableStream.cpp	2015-07-06 09:01:02 UTC (rev 186322)
+++ trunk/Source/WebCore/Modules/streams/ReadableStream.cpp	2015-07-06 09:02:29 UTC (rev 186323)
@@ -33,6 +33,7 @@
 #if ENABLE(STREAMS_API)
 
 #include "ExceptionCode.h"
+#include "ReadableJSStream.h"
 #include "ReadableStreamReader.h"
 #include "ScriptExecutionContext.h"
 #include <runtime/JSCJSValueInlines.h>
@@ -42,6 +43,11 @@
 
 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, readableStreamCounter, ("ReadableStream"));
 
+RefPtr<ReadableStream> ReadableStream::create(JSC::ExecState& state, JSC::JSValue value, const Dictionary& strategy)
+{
+    return RefPtr<ReadableStream>(ReadableJSStream::create(state, value, strategy));
+}
+
 ReadableStream::ReadableStream(ScriptExecutionContext& scriptExecutionContext)
     : ActiveDOMObject(&scriptExecutionContext)
 {

Modified: trunk/Source/WebCore/Modules/streams/ReadableStream.h (186322 => 186323)


--- trunk/Source/WebCore/Modules/streams/ReadableStream.h	2015-07-06 09:01:02 UTC (rev 186322)
+++ trunk/Source/WebCore/Modules/streams/ReadableStream.h	2015-07-06 09:02:29 UTC (rev 186323)
@@ -47,6 +47,7 @@
 
 namespace WebCore {
 
+class Dictionary;
 class ReadableStreamReader;
 class ScriptExecutionContext;
 
@@ -64,6 +65,7 @@
         Errored
     };
 
+    static RefPtr<ReadableStream> create(JSC::ExecState&, JSC::JSValue, const Dictionary&);
     virtual ~ReadableStream();
 
     ReadableStreamReader* getReader(ExceptionCode&);

Modified: trunk/Source/WebCore/Modules/streams/ReadableStream.idl (186322 => 186323)


--- trunk/Source/WebCore/Modules/streams/ReadableStream.idl	2015-07-06 09:01:02 UTC (rev 186322)
+++ trunk/Source/WebCore/Modules/streams/ReadableStream.idl	2015-07-06 09:02:29 UTC (rev 186323)
@@ -28,7 +28,8 @@
  */
 
 [
-    CustomConstructor(any properties),
+    ConstructorCallWith=ScriptState,
+    Constructor([Default=Undefined] optional any source, [Default=Undefined] optional Dictionary strategy),
     Conditional=STREAMS_API,
     SkipVTableValidation
 ] interface ReadableStream {

Modified: trunk/Source/WebCore/bindings/js/JSDictionary.cpp (186322 => 186323)


--- trunk/Source/WebCore/bindings/js/JSDictionary.cpp	2015-07-06 09:01:02 UTC (rev 186322)
+++ trunk/Source/WebCore/bindings/js/JSDictionary.cpp	2015-07-06 09:02:29 UTC (rev 186323)
@@ -265,6 +265,11 @@
 }
 #endif
 
+void JSDictionary::convertValue(JSC::ExecState*, JSC::JSValue value, JSC::JSFunction*& result)
+{
+    result = jsDynamicCast<JSC::JSFunction*>(value);
+}
+
 bool JSDictionary::getWithUndefinedOrNullCheck(const char* propertyName, String& result) const
 {
     ASSERT(isValid());

Modified: trunk/Source/WebCore/bindings/js/JSDictionary.h (186322 => 186323)


--- trunk/Source/WebCore/bindings/js/JSDictionary.h	2015-07-06 09:01:02 UTC (rev 186322)
+++ trunk/Source/WebCore/bindings/js/JSDictionary.h	2015-07-06 09:02:29 UTC (rev 186323)
@@ -137,6 +137,7 @@
 #if ENABLE(GAMEPAD)
     static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<Gamepad>&);
 #endif
+    static void convertValue(JSC::ExecState*, JSC::JSValue, JSC::JSFunction*&);
 
     JSC::ExecState* m_exec;
     JSC::Strong<JSC::JSObject> m_initializerObject;

Modified: trunk/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp (186322 => 186323)


--- trunk/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp	2015-07-06 09:01:02 UTC (rev 186322)
+++ trunk/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp	2015-07-06 09:02:29 UTC (rev 186323)
@@ -59,20 +59,6 @@
     return exec->vm().throwException(exec, error);
 }
 
-EncodedJSValue JSC_HOST_CALL constructJSReadableStream(ExecState* exec)
-{
-    DOMConstructorObject* jsConstructor = jsCast<DOMConstructorObject*>(exec->callee());
-    ASSERT(jsConstructor);
-
-    RefPtr<ReadableJSStream> readableStream = ReadableJSStream::create(*exec, *jsConstructor->scriptExecutionContext());
-
-    if (!readableStream) {
-        ASSERT(exec->hadException());
-        return JSValue::encode(jsUndefined());
-    }
-    return JSValue::encode(toJS(exec, jsCast<JSDOMGlobalObject*>(exec->callee()->globalObject()), WTF::move(readableStream)));
-}
-
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp (186322 => 186323)


--- trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp	2015-07-06 09:01:02 UTC (rev 186322)
+++ trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp	2015-07-06 09:02:29 UTC (rev 186323)
@@ -33,11 +33,13 @@
 #if ENABLE(STREAMS_API)
 
 #include "DOMWrapperWorld.h"
+#include "Dictionary.h"
 #include "ExceptionCode.h"
 #include "JSDOMPromise.h"
 #include "JSReadableStream.h"
 #include "JSReadableStreamController.h"
 #include "ScriptExecutionContext.h"
+#include "ScriptState.h"
 #include <runtime/Error.h>
 #include <runtime/Exception.h>
 #include <runtime/JSCJSValueInlines.h>
@@ -199,66 +201,43 @@
     return !promise;
 }
 
-static inline double normalizeHighWaterMark(ExecState& exec, JSObject& strategy)
+RefPtr<ReadableJSStream> ReadableJSStream::create(JSC::ExecState& state, JSC::JSValue source, const Dictionary& strategy)
 {
-    JSValue jsHighWaterMark = getPropertyFromObject(exec, strategy, "highWaterMark");
-
-    if (exec.hadException())
-        return 0;
-
-    if (jsHighWaterMark.isUndefined())
-        return 1;
-
-    double highWaterMark = jsHighWaterMark.toNumber(&exec);
-
-    if (exec.hadException())
-        return 0;
-
-    if (std::isnan(highWaterMark)) {
-        throwVMError(&exec, createTypeError(&exec, ASCIILiteral("Value is NaN")));
-        return 0;
-    }
-    if (highWaterMark < 0) {
-        throwVMError(&exec, createRangeError(&exec, ASCIILiteral("Not a positive value")));
-        return 0;
-    }
-    return highWaterMark;
-}
-
-RefPtr<ReadableJSStream> ReadableJSStream::create(ExecState& state, ScriptExecutionContext& scriptExecutionContext)
-{
-    // FIXME: We should consider reducing the binding code herei (using Dictionary/regular binding constructor and/or improving the IDL generator). 
     JSObject* jsSource;
-    JSValue value = state.argument(0);
-    if (value.isObject())
-        jsSource = value.getObject();
-    else if (!value.isUndefined()) {
-        throwVMError(&state, createTypeError(&state, ASCIILiteral("First argument, if any, should be an object")));
+    if (source.isObject())
+        jsSource = source.getObject();
+    else if (!source.isUndefined()) {
+        throwVMTypeError(&state, "Argument 1 of ReadableStream constructor must be an object");
         return nullptr;
     } else
         jsSource = JSFinalObject::create(state.vm(), JSFinalObject::createStructure(state.vm(), state.callee()->globalObject(), jsNull(), 1));
 
     double highWaterMark = 1;
     JSFunction* sizeFunction = nullptr;
-    value = state.argument(1);
-    if (value.isObject()) {
-        JSObject& strategyObject = *value.getObject();
-        highWaterMark = normalizeHighWaterMark(state, strategyObject);
-        if (state.hadException())
+    if (!strategy.isUndefinedOrNull()) {
+        if (strategy.get("highWaterMark", highWaterMark)) {
+            if (std::isnan(highWaterMark)) {
+                throwVMTypeError(&state, "'highWaterMark' of Argument 2 of ReadableStream constructor cannot be NaN");
+                return nullptr;
+            }
+            if (highWaterMark < 0) {
+                throwVMRangeError(&state, "'highWaterMark' of Argument 2 of ReadableStream constructor cannot be negative");
+                return nullptr;
+            }
+
+        } else if (state.hadException())
             return nullptr;
 
-        if (!(sizeFunction = jsDynamicCast<JSFunction*>(getPropertyFromObject(state, strategyObject, "size")))) {
-            if (!state.hadException())
-                throwVMError(&state, createTypeError(&state, ASCIILiteral("size parameter should be a function")));
+        if (strategy.get("size", sizeFunction)) {
+            if (!sizeFunction) {
+                throwVMTypeError(&state, "'size' of Argument 2 of ReadableStream constructor must be a function");
+                return nullptr;
+            }
+        } else if (state.hadException())
             return nullptr;
-        }
-        
-    } else if (!value.isUndefined()) {
-        throwVMError(&state, createTypeError(&state, ASCIILiteral("Second argument, if any, should be an object")));
-        return nullptr;
     }
 
-    RefPtr<ReadableJSStream> readableStream = adoptRef(*new ReadableJSStream(scriptExecutionContext, state, jsSource, highWaterMark, sizeFunction));
+    RefPtr<ReadableJSStream> readableStream = adoptRef(*new ReadableJSStream(state, jsSource, highWaterMark, sizeFunction));
     readableStream->doStart(state);
 
     if (state.hadException())
@@ -267,8 +246,8 @@
     return readableStream;
 }
 
-ReadableJSStream::ReadableJSStream(ScriptExecutionContext& scriptExecutionContext, ExecState& state, JSObject* source, double highWaterMark, JSFunction* sizeFunction)
-    : ReadableStream(scriptExecutionContext)
+ReadableJSStream::ReadableJSStream(ExecState& state, JSObject* source, double highWaterMark, JSFunction* sizeFunction)
+    : ReadableStream(*scriptExecutionContextFromExecState(&state))
     , m_highWaterMark(highWaterMark)
 {
     m_source.set(state.vm(), source);

Modified: trunk/Source/WebCore/bindings/js/ReadableJSStream.h (186322 => 186323)


--- trunk/Source/WebCore/bindings/js/ReadableJSStream.h	2015-07-06 09:01:02 UTC (rev 186322)
+++ trunk/Source/WebCore/bindings/js/ReadableJSStream.h	2015-07-06 09:02:29 UTC (rev 186323)
@@ -54,7 +54,7 @@
 
 class ReadableJSStream: public ReadableStream {
 public:
-    static RefPtr<ReadableJSStream> create(JSC::ExecState&, ScriptExecutionContext&);
+    static RefPtr<ReadableJSStream> create(JSC::ExecState&, JSC::JSValue, const Dictionary&);
 
     JSC::JSValue jsController(JSC::ExecState&, JSDOMGlobalObject*);
     void close(ExceptionCode&);
@@ -68,7 +68,7 @@
     double desiredSize() const { return m_highWaterMark - m_totalQueueSize; }
 
 private:
-    ReadableJSStream(ScriptExecutionContext&, JSC::ExecState&, JSC::JSObject*, double, JSC::JSFunction*);
+    ReadableJSStream(JSC::ExecState&, JSC::JSObject*, double, JSC::JSFunction*);
 
     void doStart(JSC::ExecState&);
 

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (186322 => 186323)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2015-07-06 09:01:02 UTC (rev 186322)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2015-07-06 09:02:29 UTC (rev 186323)
@@ -4660,6 +4660,9 @@
             my $numParameters = @{$function->parameters};
             my ($dummy, $paramIndex) = GenerateParametersCheck($outputArray, $function, $interface, $numParameters, $interfaceName, "constructorCallback", undef, undef, undef);
 
+            if ($codeGenerator->ExtendedAttributeContains($interface->extendedAttributes->{"ConstructorCallWith"}, "ScriptState")) {
+                push(@constructorArgList, "*exec");
+            }
             if ($codeGenerator->ExtendedAttributeContains($interface->extendedAttributes->{"ConstructorCallWith"}, "ScriptExecutionContext")) {
                 push(@constructorArgList, "*context");
                 push(@$outputArray, "    ScriptExecutionContext* context = castedThis->scriptExecutionContext();\n");
@@ -4702,6 +4705,11 @@
                 push(@$outputArray, "    }\n");
             }
 
+            if ($codeGenerator->ExtendedAttributeContains($interface->extendedAttributes->{"ConstructorCallWith"}, "ScriptState")) {
+                 push(@$outputArray, "    if (UNLIKELY(exec->hadException()))\n");
+                 push(@$outputArray, "        return JSValue::encode(jsUndefined());\n");
+            }
+
             push(@$outputArray, "    return JSValue::encode(asObject(toJS(exec, castedThis->globalObject(), object.get())));\n");
             push(@$outputArray, "}\n\n");
         }

Modified: trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt (186322 => 186323)


--- trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt	2015-07-06 09:01:02 UTC (rev 186322)
+++ trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt	2015-07-06 09:02:29 UTC (rev 186323)
@@ -29,7 +29,7 @@
 Clamp
 Conditional=*
 Constructor
-ConstructorCallWith=Document|ScriptExecutionContext
+ConstructorCallWith=Document|ScriptExecutionContext|ScriptState
 ConstructorConditional=*
 ConstructorRaisesException
 ConstructorTemplate=Event|TypedArray
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to