| 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 "core/streams/ReadableStreamOperations.h" | 5 #include "core/streams/ReadableStreamOperations.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ScriptFunction.h" | 8 #include "bindings/core/v8/ScriptFunction.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "bindings/core/v8/ScriptValue.h" | 10 #include "bindings/core/v8/ScriptValue.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 public: | 47 public: |
| 48 Iteration() : is_set_(false), is_done_(false), is_valid_(true) {} | 48 Iteration() : is_set_(false), is_done_(false), is_valid_(true) {} |
| 49 | 49 |
| 50 void Set(ScriptValue v) { | 50 void Set(ScriptValue v) { |
| 51 ASSERT(!v.IsEmpty()); | 51 ASSERT(!v.IsEmpty()); |
| 52 is_set_ = true; | 52 is_set_ = true; |
| 53 v8::TryCatch block(v.GetScriptState()->GetIsolate()); | 53 v8::TryCatch block(v.GetScriptState()->GetIsolate()); |
| 54 v8::Local<v8::Value> value; | 54 v8::Local<v8::Value> value; |
| 55 v8::Local<v8::Value> item = v.V8Value(); | 55 v8::Local<v8::Value> item = v.V8Value(); |
| 56 if (!item->IsObject() || | 56 if (!item->IsObject() || |
| 57 !V8Call(V8UnpackIteratorResult(v.GetScriptState(), | 57 !V8UnpackIteratorResult(v.GetScriptState(), item.As<v8::Object>(), |
| 58 item.As<v8::Object>(), &is_done_), | 58 &is_done_) |
| 59 value)) { | 59 .ToLocal(&value)) { |
| 60 is_valid_ = false; | 60 is_valid_ = false; |
| 61 return; | 61 return; |
| 62 } | 62 } |
| 63 value_ = ToCoreString(value->ToString()); | 63 value_ = ToCoreString(value->ToString()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool IsSet() const { return is_set_; } | 66 bool IsSet() const { return is_set_; } |
| 67 bool IsDone() const { return is_done_; } | 67 bool IsDone() const { return is_done_; } |
| 68 bool IsValid() const { return is_valid_; } | 68 bool IsValid() const { return is_valid_; } |
| 69 const String& Value() const { return value_; } | 69 const String& Value() const { return value_; } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 private: | 127 private: |
| 128 v8::Isolate* isolate_; | 128 v8::Isolate* isolate_; |
| 129 v8::TryCatch trycatch_; | 129 v8::TryCatch trycatch_; |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 ScriptValue Eval(V8TestingScope* scope, const char* s) { | 132 ScriptValue Eval(V8TestingScope* scope, const char* s) { |
| 133 v8::Local<v8::String> source; | 133 v8::Local<v8::String> source; |
| 134 v8::Local<v8::Script> script; | 134 v8::Local<v8::Script> script; |
| 135 v8::MicrotasksScope microtasks(scope->GetIsolate(), | 135 v8::MicrotasksScope microtasks(scope->GetIsolate(), |
| 136 v8::MicrotasksScope::kDoNotRunMicrotasks); | 136 v8::MicrotasksScope::kDoNotRunMicrotasks); |
| 137 if (!V8Call(v8::String::NewFromUtf8(scope->GetIsolate(), s, | 137 if (!v8::String::NewFromUtf8(scope->GetIsolate(), s, |
| 138 v8::NewStringType::kNormal), | 138 v8::NewStringType::kNormal) |
| 139 source)) { | 139 .ToLocal(&source)) { |
| 140 ADD_FAILURE(); | 140 ADD_FAILURE(); |
| 141 return ScriptValue(); | 141 return ScriptValue(); |
| 142 } | 142 } |
| 143 if (!V8Call(v8::Script::Compile(scope->GetContext(), source), script)) { | 143 if (!v8::Script::Compile(scope->GetContext(), source).ToLocal(&script)) { |
| 144 ADD_FAILURE() << "Compilation fails"; | 144 ADD_FAILURE() << "Compilation fails"; |
| 145 return ScriptValue(); | 145 return ScriptValue(); |
| 146 } | 146 } |
| 147 return ScriptValue(scope->GetScriptState(), script->Run(scope->GetContext())); | 147 return ScriptValue(scope->GetScriptState(), script->Run(scope->GetContext())); |
| 148 } | 148 } |
| 149 | 149 |
| 150 ScriptValue EvalWithPrintingError(V8TestingScope* scope, const char* s) { | 150 ScriptValue EvalWithPrintingError(V8TestingScope* scope, const char* s) { |
| 151 v8::TryCatch block(scope->GetIsolate()); | 151 v8::TryCatch block(scope->GetIsolate()); |
| 152 ScriptValue r = Eval(scope, s); | 152 ScriptValue r = Eval(scope, s); |
| 153 if (block.HasCaught()) { | 153 if (block.HasCaught()) { |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 EXPECT_EQ("hello", it1->Value()); | 494 EXPECT_EQ("hello", it1->Value()); |
| 495 EXPECT_TRUE(it2->IsSet()); | 495 EXPECT_TRUE(it2->IsSet()); |
| 496 EXPECT_TRUE(it2->IsValid()); | 496 EXPECT_TRUE(it2->IsValid()); |
| 497 EXPECT_FALSE(it2->IsDone()); | 497 EXPECT_FALSE(it2->IsDone()); |
| 498 EXPECT_EQ("hello", it2->Value()); | 498 EXPECT_EQ("hello", it2->Value()); |
| 499 } | 499 } |
| 500 | 500 |
| 501 } // namespace | 501 } // namespace |
| 502 | 502 |
| 503 } // namespace blink | 503 } // namespace blink |
| OLD | NEW |