OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/streams/ReadableStreamReader.h" | 6 #include "core/streams/ReadableStreamReader.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "bindings/core/v8/ToV8.h" | 10 #include "bindings/core/v8/ToV8.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 struct ReadResult { | 27 struct ReadResult { |
28 ReadResult() : isDone(false), isSet(false) { } | 28 ReadResult() : isDone(false), isSet(false) { } |
29 | 29 |
30 String valueString; | 30 String valueString; |
31 bool isDone; | 31 bool isDone; |
32 bool isSet; | 32 bool isSet; |
33 }; | 33 }; |
34 | 34 |
35 class StringCapturingFunction final : public ScriptFunction { | 35 class StringCapturingFunction final : public ScriptFunction { |
36 public: | 36 public: |
37 static v8::Handle<v8::Function> createFunction(ScriptState* scriptState, Str
ing* value) | 37 static v8::Local<v8::Function> createFunction(ScriptState* scriptState, Stri
ng* value) |
38 { | 38 { |
39 StringCapturingFunction* self = new StringCapturingFunction(scriptState,
value); | 39 StringCapturingFunction* self = new StringCapturingFunction(scriptState,
value); |
40 return self->bindToV8Function(); | 40 return self->bindToV8Function(); |
41 } | 41 } |
42 | 42 |
43 private: | 43 private: |
44 StringCapturingFunction(ScriptState* scriptState, String* value) | 44 StringCapturingFunction(ScriptState* scriptState, String* value) |
45 : ScriptFunction(scriptState) | 45 : ScriptFunction(scriptState) |
46 , m_value(value) | 46 , m_value(value) |
47 { | 47 { |
48 } | 48 } |
49 | 49 |
50 ScriptValue call(ScriptValue value) override | 50 ScriptValue call(ScriptValue value) override |
51 { | 51 { |
52 ASSERT(!value.isEmpty()); | 52 ASSERT(!value.isEmpty()); |
53 *m_value = toCoreString(value.v8Value()->ToString(scriptState()->context
()).ToLocalChecked()); | 53 *m_value = toCoreString(value.v8Value()->ToString(scriptState()->context
()).ToLocalChecked()); |
54 return value; | 54 return value; |
55 } | 55 } |
56 | 56 |
57 String* m_value; | 57 String* m_value; |
58 }; | 58 }; |
59 | 59 |
60 class ReadResultCapturingFunction final : public ScriptFunction { | 60 class ReadResultCapturingFunction final : public ScriptFunction { |
61 public: | 61 public: |
62 static v8::Handle<v8::Function> createFunction(ScriptState* scriptState, Rea
dResult* value) | 62 static v8::Local<v8::Function> createFunction(ScriptState* scriptState, Read
Result* value) |
63 { | 63 { |
64 ReadResultCapturingFunction* self = new ReadResultCapturingFunction(scri
ptState, value); | 64 ReadResultCapturingFunction* self = new ReadResultCapturingFunction(scri
ptState, value); |
65 return self->bindToV8Function(); | 65 return self->bindToV8Function(); |
66 } | 66 } |
67 | 67 |
68 private: | 68 private: |
69 ReadResultCapturingFunction(ScriptState* scriptState, ReadResult* value) | 69 ReadResultCapturingFunction(ScriptState* scriptState, ReadResult* value) |
70 : ScriptFunction(scriptState) | 70 : ScriptFunction(scriptState) |
71 , m_result(value) | 71 , m_result(value) |
72 { | 72 { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 // We need to call |error| in order to make | 139 // We need to call |error| in order to make |
140 // ActiveDOMObject::hasPendingActivity return false. | 140 // ActiveDOMObject::hasPendingActivity return false. |
141 m_stream->error(DOMException::create(AbortError, "done")); | 141 m_stream->error(DOMException::create(AbortError, "done")); |
142 } | 142 } |
143 | 143 |
144 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume
nt().frame()); } | 144 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume
nt().frame()); } |
145 v8::Isolate* isolate() { return scriptState()->isolate(); } | 145 v8::Isolate* isolate() { return scriptState()->isolate(); } |
146 ExecutionContext* executionContext() { return scriptState()->executionContex
t(); } | 146 ExecutionContext* executionContext() { return scriptState()->executionContex
t(); } |
147 | 147 |
148 v8::Handle<v8::Function> createCaptor(String* value) | 148 v8::Local<v8::Function> createCaptor(String* value) |
149 { | 149 { |
150 return StringCapturingFunction::createFunction(scriptState(), value); | 150 return StringCapturingFunction::createFunction(scriptState(), value); |
151 } | 151 } |
152 | 152 |
153 v8::Handle<v8::Function> createResultCaptor(ReadResult* value) | 153 v8::Local<v8::Function> createResultCaptor(ReadResult* value) |
154 { | 154 { |
155 return ReadResultCapturingFunction::createFunction(scriptState(), value)
; | 155 return ReadResultCapturingFunction::createFunction(scriptState(), value)
; |
156 } | 156 } |
157 | 157 |
158 OwnPtr<DummyPageHolder> m_page; | 158 OwnPtr<DummyPageHolder> m_page; |
159 ScriptState::Scope m_scope; | 159 ScriptState::Scope m_scope; |
160 ExceptionState m_exceptionState; | 160 ExceptionState m_exceptionState; |
161 Persistent<StringStream> m_stream; | 161 Persistent<StringStream> m_stream; |
162 }; | 162 }; |
163 | 163 |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 EXPECT_TRUE(onRejected.isNull()); | 542 EXPECT_TRUE(onRejected.isNull()); |
543 | 543 |
544 isolate()->RunMicrotasks(); | 544 isolate()->RunMicrotasks(); |
545 EXPECT_TRUE(onFulfilled.isNull()); | 545 EXPECT_TRUE(onFulfilled.isNull()); |
546 EXPECT_EQ("SyntaxError: some error", onRejected); | 546 EXPECT_EQ("SyntaxError: some error", onRejected); |
547 } | 547 } |
548 | 548 |
549 } // namespace | 549 } // namespace |
550 | 550 |
551 } // namespace blink | 551 } // namespace blink |
OLD | NEW |