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 "bindings/core/v8/ReadableStreamOperations.h" | 6 #include "bindings/core/v8/ReadableStreamOperations.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptFunction.h" | 9 #include "bindings/core/v8/ScriptFunction.h" |
10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
11 #include "bindings/core/v8/V8Binding.h" | 11 #include "bindings/core/v8/V8Binding.h" |
12 #include "bindings/core/v8/V8BindingForTesting.h" | 12 #include "bindings/core/v8/V8BindingForTesting.h" |
13 #include "bindings/core/v8/V8BindingMacros.h" | 13 #include "bindings/core/v8/V8BindingMacros.h" |
14 #include "bindings/core/v8/V8IteratorResultValue.h" | 14 #include "bindings/core/v8/V8IteratorResultValue.h" |
15 #include "bindings/core/v8/V8ThrowException.h" | 15 #include "bindings/core/v8/V8ThrowException.h" |
16 #include "platform/heap/Handle.h" | 16 #include "platform/heap/Handle.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include <v8.h> | 18 #include <v8.h> |
19 | 19 |
20 namespace blink { | 20 namespace blink { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Unpacks |item|, stores the value of "done" member to |done| and returns | |
25 // the value of "value" member. Returns an empty handle when errored. | |
26 v8::MaybeLocal<v8::Value> unpack(ScriptState* scriptState, v8::Local<v8::Value>
item, bool* done) | |
27 { | |
28 if (!item->IsObject()) { | |
29 V8ThrowException::throwTypeError(scriptState->isolate(), "The iteration
item is not an object."); | |
30 return v8::MaybeLocal<v8::Value>(); | |
31 } | |
32 v8::Local<v8::Object> object = item.As<v8::Object>(); | |
33 v8::Local<v8::Value> doneValue; | |
34 if (!v8Call(object->Get(scriptState->context(), v8String(scriptState->isolat
e(), "done")), doneValue)) | |
35 return v8::MaybeLocal<v8::Value>(); | |
36 v8::MaybeLocal<v8::Value> r = object->Get(scriptState->context(), v8String(s
criptState->isolate(), "value")); | |
37 if (!r.IsEmpty()) | |
38 *done = doneValue->ToBoolean()->Value(); | |
39 return r; | |
40 } | |
41 | |
42 class NotReached : public ScriptFunction { | 24 class NotReached : public ScriptFunction { |
43 public: | 25 public: |
44 static v8::Local<v8::Function> createFunction(ScriptState* scriptState) | 26 static v8::Local<v8::Function> createFunction(ScriptState* scriptState) |
45 { | 27 { |
46 NotReached* self = new NotReached(scriptState); | 28 NotReached* self = new NotReached(scriptState); |
47 return self->bindToV8Function(); | 29 return self->bindToV8Function(); |
48 } | 30 } |
49 | 31 |
50 private: | 32 private: |
51 explicit NotReached(ScriptState* scriptState) | 33 explicit NotReached(ScriptState* scriptState) |
(...skipping 16 matching lines...) Expand all Loading... |
68 : m_isSet(false) | 50 : m_isSet(false) |
69 , m_isDone(false) | 51 , m_isDone(false) |
70 , m_isValid(true) {} | 52 , m_isValid(true) {} |
71 | 53 |
72 void set(ScriptValue v) | 54 void set(ScriptValue v) |
73 { | 55 { |
74 ASSERT(!v.isEmpty()); | 56 ASSERT(!v.isEmpty()); |
75 m_isSet = true; | 57 m_isSet = true; |
76 v8::TryCatch block(v.scriptState()->isolate()); | 58 v8::TryCatch block(v.scriptState()->isolate()); |
77 v8::Local<v8::Value> value; | 59 v8::Local<v8::Value> value; |
78 if (!v8Call(unpack(v.scriptState(), v.v8Value(), &m_isDone), value)) { | 60 v8::Local<v8::Value> item = v.v8Value(); |
| 61 if (!item->IsObject() || !v8Call(v8IterationItemUnpack(v.scriptState(),
item.As<v8::Object>(), &m_isDone), value)) { |
79 m_isValid = false; | 62 m_isValid = false; |
80 return; | 63 return; |
81 } | 64 } |
82 m_value = toCoreString(value->ToString()); | 65 m_value = toCoreString(value->ToString()); |
83 } | 66 } |
84 | 67 |
85 bool isSet() const { return m_isSet; } | 68 bool isSet() const { return m_isSet; } |
86 bool isDone() const { return m_isDone; } | 69 bool isDone() const { return m_isDone; } |
87 bool isValid() const { return m_isValid; } | 70 bool isValid() const { return m_isValid; } |
88 const String& value() const { return m_value; } | 71 const String& value() const { return m_value; } |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 EXPECT_EQ("hello", it1->value()); | 249 EXPECT_EQ("hello", it1->value()); |
267 EXPECT_TRUE(it2->isSet()); | 250 EXPECT_TRUE(it2->isSet()); |
268 EXPECT_TRUE(it2->isValid()); | 251 EXPECT_TRUE(it2->isValid()); |
269 EXPECT_TRUE(it2->isDone()); | 252 EXPECT_TRUE(it2->isDone()); |
270 } | 253 } |
271 | 254 |
272 } // namespace | 255 } // namespace |
273 | 256 |
274 } // namespace blink | 257 } // namespace blink |
275 | 258 |
OLD | NEW |