Changeset 185537 in webkit
- Timestamp:
- Jun 13, 2015 2:09:53 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r185536 r185537 1 2015-06-13 Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet <youenn.fablet@crf.canon.fr> 2 3 [Streams API] ReadableJSStream should handle promises returned by JS source start callback 4 https://bugs.webkit.org/show_bug.cgi?id=145792 5 6 Reviewed by Darin Adler. 7 8 Rebasing expectations, and removing timeouts for tests that no longer timeout. 9 10 * streams/reference-implementation/readable-stream-expected.txt: 11 * streams/reference-implementation/readable-stream.html: 12 1 13 2015-06-13 Andres Gonzalez <agonzalez334@nc.rr.com> 2 14 -
trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt
r185467 r185537 6 6 PASS ReadableStream constructor can get initial garbage as pull argument 7 7 PASS ReadableStream constructor can get initial garbage as strategy argument 8 TIMEOUT ReadableStream start should be able to return a promise Test timed out 9 TIMEOUT ReadableStream start should be able to return a promise and reject it Test timed out 8 PASS ReadableStream start should be able to return a promise 9 PASS ReadableStream start should be able to return a promise and reject it 10 10 PASS ReadableStream should be able to enqueue different objects. 11 11 PASS ReadableStream: if start throws an error, it should be re-thrown … … 21 21 FAIL ReadableStream strategies: the default strategy should return false for all but the first enqueue call assert_equals: first enqueue should return true expected (boolean) true but got (undefined) undefined 22 22 FAIL ReadableStream strategies: the default strategy should continue returning true from enqueue if the chunks are read immediately assert_equals: first enqueue should return true expected (boolean) true but got (undefined) undefined 23 TIMEOUT ReadableStream integration test: adapting a random push source Test timed out 23 PASS ReadableStream integration test: adapting a random push source 24 24 PASS ReadableStream integration test: adapting a sync pull source 25 25 -
trunk/LayoutTests/streams/reference-implementation/readable-stream.html
r185467 r185537 54 54 }, 'ReadableStream constructor can get initial garbage as strategy argument'); 55 55 56 var test1 = async_test('ReadableStream start should be able to return a promise' , { timeout: 50 });56 var test1 = async_test('ReadableStream start should be able to return a promise'); 57 57 test1.step(function() 58 58 { … … 83 83 }); 84 84 85 var test2 = async_test('ReadableStream start should be able to return a promise and reject it' , { timeout: 100 });85 var test2 = async_test('ReadableStream start should be able to return a promise and reject it'); 86 86 test2.step(function() 87 87 { … … 659 659 }); 660 660 661 var test18 = async_test('ReadableStream integration test: adapting a random push source' , { timeout: 50 });661 var test18 = async_test('ReadableStream integration test: adapting a random push source'); 662 662 test18.step(function() { 663 663 var pullChecked = false; -
trunk/Source/JavaScriptCore/ChangeLog
r185532 r185537 1 2015-06-13 Youenn Fablet <youenn.fablet@crf.canon.fr> 2 3 [Streams API] ReadableJSStream should handle promises returned by JS source start callback 4 https://bugs.webkit.org/show_bug.cgi?id=145792 5 6 Reviewed by Darin Adler. 7 8 Added support for JSFunction implemented by std::function. 9 10 * runtime/JSFunction.cpp: 11 (JSC::getNativeExecutable): Refactored code to share it with the two JSFunction::create 12 (JSC::JSFunction::create): 13 (JSC::runStdFunction): 14 * runtime/JSFunction.h: Added std::function based JSFunction::create prototype. 15 * runtime.JSPromise.h: 16 1 17 2015-06-12 Gyuyoung Kim <gyuyoung.kim@webkit.org> 2 18 -
trunk/Source/JavaScriptCore/runtime/JSFunction.cpp
r185467 r185537 5 5 * Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca) 6 6 * Copyright (C) 2007 Maks Orlovich 7 * Copyright (C) 2015 Canon Inc. All rights reserved. 7 8 * 8 9 * This library is free software; you can redistribute it and/or … … 67 68 } 68 69 69 JSFunction* JSFunction::create(VM& vm, JSGlobalObject* globalObject, int length, const String& name, NativeFunction nativeFunction, Intrinsic intrinsic, NativeFunction nativeConstructor) 70 { 71 NativeExecutable* executable; 70 static inline NativeExecutable* getNativeExecutable(VM& vm, NativeFunction nativeFunction, Intrinsic intrinsic, NativeFunction nativeConstructor) 71 { 72 72 #if !ENABLE(JIT) 73 73 UNUSED_PARAM(intrinsic); … … 75 75 if (intrinsic != NoIntrinsic && vm.canUseJIT()) { 76 76 ASSERT(nativeConstructor == callHostFunctionAsConstructor); 77 executable =vm.getHostFunction(nativeFunction, intrinsic);78 } else77 return vm.getHostFunction(nativeFunction, intrinsic); 78 } 79 79 #endif 80 executable = vm.getHostFunction(nativeFunction, nativeConstructor); 81 80 return vm.getHostFunction(nativeFunction, nativeConstructor); 81 } 82 83 JSFunction* JSFunction::create(VM& vm, JSGlobalObject* globalObject, int length, const String& name, NativeFunction nativeFunction, Intrinsic intrinsic, NativeFunction nativeConstructor) 84 { 85 NativeExecutable* executable = getNativeExecutable(vm, nativeFunction, intrinsic, nativeConstructor); 82 86 JSFunction* function = new (NotNull, allocateCell<JSFunction>(vm.heap)) JSFunction(vm, globalObject, globalObject->functionStructure()); 87 // Can't do this during initialization because getHostFunction might do a GC allocation. 88 function->finishCreation(vm, executable, length, name); 89 return function; 90 } 91 92 class JSStdFunction : public JSFunction { 93 public: 94 JSStdFunction(VM& vm, JSGlobalObject* object, Structure* structure, NativeStdFunction&& function) 95 : JSFunction(vm, object, structure) 96 , stdFunction(WTF::move(function)) { } 97 98 NativeStdFunction stdFunction; 99 }; 100 101 static EncodedJSValue JSC_HOST_CALL runStdFunction(ExecState* state) 102 { 103 JSStdFunction* jsFunction = jsCast<JSStdFunction*>(state->callee()); 104 ASSERT(jsFunction); 105 return jsFunction->stdFunction(state); 106 } 107 108 JSFunction* JSFunction::create(VM& vm, JSGlobalObject* globalObject, int length, const String& name, NativeStdFunction&& nativeStdFunction, Intrinsic intrinsic, NativeFunction nativeConstructor) 109 { 110 NativeExecutable* executable = getNativeExecutable(vm, runStdFunction, intrinsic, nativeConstructor); 111 JSStdFunction* function = new (NotNull, allocateCell<JSStdFunction>(vm.heap)) JSStdFunction(vm, globalObject, globalObject->functionStructure(), WTF::move(nativeStdFunction)); 83 112 // Can't do this during initialization because getHostFunction might do a GC allocation. 84 113 function->finishCreation(vm, executable, length, name); -
trunk/Source/JavaScriptCore/runtime/JSFunction.h
r185467 r185537 46 46 } 47 47 48 typedef std::function<EncodedJSValue (ExecState*)> NativeStdFunction; 49 48 50 JS_EXPORT_PRIVATE EncodedJSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState*); 49 51 … … 69 71 70 72 static JSFunction* createWithInvalidatedReallocationWatchpoint(VM&, FunctionExecutable*, JSScope*); 73 JS_EXPORT_PRIVATE static JSFunction* create(VM&, JSGlobalObject*, int length, const String& name, NativeStdFunction&&, Intrinsic = NoIntrinsic, NativeFunction nativeConstructor = callHostFunctionAsConstructor); 71 74 72 75 static JSFunction* create(VM&, FunctionExecutable*, JSScope*); -
trunk/Source/JavaScriptCore/runtime/JSPromise.h
r185467 r185537 43 43 static Structure* createStructure(VM&, JSGlobalObject*, JSValue); 44 44 45 DECLARE_ INFO;45 DECLARE_EXPORT_INFO; 46 46 47 47 enum class Status { -
trunk/Source/WebCore/ChangeLog
r185536 r185537 1 2015-06-13 Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet <youenn.fablet@crf.canon.fr> 2 3 [Streams API] ReadableJSStream should handle promises returned by JS source start callback 4 https://bugs.webkit.org/show_bug.cgi?id=145792 5 6 Reviewed by Darin Adler. 7 8 Covered by rebased tests. 9 10 When calling start callback, the returned value is checked. 11 If it is not a promise, we do as if it is a resolved promise. 12 If it is a promise, we call its then() method with two resolve/reject JS functions. 13 14 * Modules/streams/ReadableStream.cpp: 15 * bindings/js/ReadableJSStream.cpp: 16 (WebCore::ReadableJSStream::invoke): Returns a JSPromise* if any is returned by the JS source callback. 17 (WebCore::thenPromise): Utility method to call the promise. 18 (WebCore::createStartResultFulfilledFunction): The promise resolve callback. 19 (WebCore::ReadableJSStream::doStart): Calls thenPromise if a JSPromise* is returned by invoke. 20 (WebCore::ReadableJSStream::ReadableJSStream): 21 * bindings/js/ReadableJSStream.h: 22 1 23 2015-06-13 Andres Gonzalez <agonzalez334@nc.rr.com> 2 24 -
trunk/Source/WebCore/Modules/streams/ReadableStream.cpp
r185467 r185537 33 33 #if ENABLE(STREAMS_API) 34 34 35 #include "NotImplemented.h"36 35 #include "ReadableStreamReader.h" 37 36 #include <runtime/JSCJSValueInlines.h> -
trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp
r185467 r185537 37 37 #include "JSReadableStream.h" 38 38 #include "JSReadableStreamController.h" 39 #include "NotImplemented.h"40 39 #include "ScriptExecutionContext.h" 41 40 #include <runtime/Error.h> 42 41 #include <runtime/Exception.h> 43 42 #include <runtime/JSCJSValueInlines.h> 43 #include <runtime/JSPromise.h> 44 44 #include <runtime/JSString.h> 45 45 #include <runtime/StructureInlines.h> … … 61 61 } 62 62 63 JS Value ReadableJSStream::invoke(ExecState& exec, const char* propertyName)64 { 65 JSValue function = getPropertyFromObject( exec, m_source.get(), propertyName);66 if ( exec.hadException())67 return jsUndefined();63 JSPromise* ReadableJSStream::invoke(ExecState& state, const char* propertyName) 64 { 65 JSValue function = getPropertyFromObject(state, m_source.get(), propertyName); 66 if (state.hadException()) 67 return nullptr; 68 68 69 69 if (!function.isFunction()) { 70 70 if (!function.isUndefined()) 71 throwVMError(& exec, createTypeError(&exec, ASCIILiteral("ReadableStream trying to call a property that is not callable")));72 return jsUndefined();71 throwVMError(&state, createTypeError(&state, ASCIILiteral("ReadableStream trying to call a property that is not callable"))); 72 return nullptr; 73 73 } 74 74 75 75 MarkedArgumentBuffer arguments; 76 arguments.append(jsController(exec, globalObject())); 77 return callFunction(exec, function, m_source.get(), arguments); 76 arguments.append(jsController(state, globalObject())); 77 78 JSPromise* promise = jsDynamicCast<JSPromise*>(callFunction(state, function, m_source.get(), arguments)); 79 80 ASSERT(!(promise && state.hadException())); 81 return promise; 82 } 83 84 static void thenPromise(ExecState& state, JSPromise* deferredPromise, JSValue fullfilFunction, JSValue rejectFunction) 85 { 86 JSValue thenValue = deferredPromise->get(&state, state.vm().propertyNames->then); 87 if (state.hadException()) 88 return; 89 90 MarkedArgumentBuffer arguments; 91 arguments.append(fullfilFunction); 92 arguments.append(rejectFunction); 93 94 callFunction(state, thenValue, deferredPromise, arguments); 78 95 } 79 96 … … 83 100 } 84 101 85 static void startReadableStreamAsync(ReadableStream& readableStream) 102 static inline JSFunction* createStartResultFulfilledFunction(ExecState& state, ReadableStream& readableStream) 103 { 104 RefPtr<ReadableStream> stream = &readableStream; 105 return JSFunction::create(state.vm(), state.callee()->globalObject(), 1, String(), [stream](ExecState*) { 106 stream->start(); 107 return JSValue::encode(jsUndefined()); 108 }); 109 } 110 111 static inline void startReadableStreamAsync(ReadableStream& readableStream) 86 112 { 87 113 RefPtr<ReadableStream> stream = &readableStream; … … 95 121 JSLockHolder lock(&exec); 96 122 97 invoke(exec, "start");123 JSPromise* promise = invoke(exec, "start"); 98 124 99 125 if (exec.hadException()) 100 126 return; 101 127 102 // FIXME: Implement handling promise as result of calling start function. 103 startReadableStreamAsync(*this); 128 if (!promise) { 129 startReadableStreamAsync(*this); 130 return; 131 } 132 133 thenPromise(exec, promise, createStartResultFulfilledFunction(exec, *this), m_errorFunction.get()); 104 134 } 105 135 … … 140 170 } 141 171 142 ReadableJSStream::ReadableJSStream(ScriptExecutionContext& scriptExecutionContext, ExecState& exec, JSObject* source)172 ReadableJSStream::ReadableJSStream(ScriptExecutionContext& scriptExecutionContext, ExecState& state, JSObject* source) 143 173 : ReadableStream(scriptExecutionContext) 144 174 { 145 m_source.set(exec.vm(), source); 175 m_source.set(state.vm(), source); 176 // We do not take a Ref to the stream as this would cause a Ref cycle. 177 // The resolution callback used jointly with m_errorFunction as promise callbacks should protect the stream instead. 178 m_errorFunction.set(state.vm(), JSFunction::create(state.vm(), state.callee()->globalObject(), 1, String(), [this](ExecState* state) { 179 storeError(*state); 180 return JSValue::encode(jsUndefined()); 181 })); 146 182 } 147 183 -
trunk/Source/WebCore/bindings/js/ReadableJSStream.h
r185518 r185537 41 41 #include <wtf/Ref.h> 42 42 43 namespace JSC { 44 class JSFunction; 45 class JSPromise; 46 } 47 43 48 namespace WebCore { 44 49 … … 62 67 void doStart(JSC::ExecState&); 63 68 64 JSC::JS Valueinvoke(JSC::ExecState&, const char*);69 JSC::JSPromise* invoke(JSC::ExecState&, const char*); 65 70 void storeException(JSC::ExecState&); 66 71 void storeError(JSC::ExecState&, JSC::JSValue); … … 74 79 std::unique_ptr<ReadableStreamController> m_controller; 75 80 JSC::Strong<JSC::Unknown> m_error; 81 JSC::Strong<JSC::JSFunction> m_errorFunction; 76 82 JSC::Strong<JSC::JSObject> m_source; 77 83 Deque<JSC::Strong<JSC::Unknown>> m_chunkQueue;
Note: See TracChangeset
for help on using the changeset viewer.