Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ReadableStreamOperationsTest.cpp

Issue 1527493002: Revert of Response construction with a ReadableStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
24 class NotReached : public ScriptFunction { 42 class NotReached : public ScriptFunction {
25 public: 43 public:
26 static v8::Local<v8::Function> createFunction(ScriptState* scriptState) 44 static v8::Local<v8::Function> createFunction(ScriptState* scriptState)
27 { 45 {
28 NotReached* self = new NotReached(scriptState); 46 NotReached* self = new NotReached(scriptState);
29 return self->bindToV8Function(); 47 return self->bindToV8Function();
30 } 48 }
31 49
32 private: 50 private:
33 explicit NotReached(ScriptState* scriptState) 51 explicit NotReached(ScriptState* scriptState)
(...skipping 16 matching lines...) Expand all
50 : m_isSet(false) 68 : m_isSet(false)
51 , m_isDone(false) 69 , m_isDone(false)
52 , m_isValid(true) {} 70 , m_isValid(true) {}
53 71
54 void set(ScriptValue v) 72 void set(ScriptValue v)
55 { 73 {
56 ASSERT(!v.isEmpty()); 74 ASSERT(!v.isEmpty());
57 m_isSet = true; 75 m_isSet = true;
58 v8::TryCatch block(v.scriptState()->isolate()); 76 v8::TryCatch block(v.scriptState()->isolate());
59 v8::Local<v8::Value> value; 77 v8::Local<v8::Value> value;
60 v8::Local<v8::Value> item = v.v8Value(); 78 if (!v8Call(unpack(v.scriptState(), v.v8Value(), &m_isDone), value)) {
61 if (!item->IsObject() || !v8Call(v8UnpackIteratorResult(v.scriptState(), item.As<v8::Object>(), &m_isDone), value)) {
62 m_isValid = false; 79 m_isValid = false;
63 return; 80 return;
64 } 81 }
65 m_value = toCoreString(value->ToString()); 82 m_value = toCoreString(value->ToString());
66 } 83 }
67 84
68 bool isSet() const { return m_isSet; } 85 bool isSet() const { return m_isSet; }
69 bool isDone() const { return m_isDone; } 86 bool isDone() const { return m_isDone; }
70 bool isValid() const { return m_isValid; } 87 bool isValid() const { return m_isValid; }
71 const String& value() const { return m_value; } 88 const String& value() const { return m_value; }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 EXPECT_EQ("hello", it1->value()); 266 EXPECT_EQ("hello", it1->value());
250 EXPECT_TRUE(it2->isSet()); 267 EXPECT_TRUE(it2->isSet());
251 EXPECT_TRUE(it2->isValid()); 268 EXPECT_TRUE(it2->isValid());
252 EXPECT_TRUE(it2->isDone()); 269 EXPECT_TRUE(it2->isDone());
253 } 270 }
254 271
255 } // namespace 272 } // namespace
256 273
257 } // namespace blink 274 } // namespace blink
258 275
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698