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

Side by Side Diff: Source/bindings/v8/ScriptPromiseResolver.cpp

Issue 273683006: ScriptPromise should understand the ScriptState from which the ScriptPromise is generated (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 months 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 23 matching lines...) Expand all
34 #include "RuntimeEnabledFeatures.h" 34 #include "RuntimeEnabledFeatures.h"
35 #include "bindings/v8/ScriptValue.h" 35 #include "bindings/v8/ScriptValue.h"
36 #include "bindings/v8/V8Binding.h" 36 #include "bindings/v8/V8Binding.h"
37 #include "bindings/v8/V8DOMWrapper.h" 37 #include "bindings/v8/V8DOMWrapper.h"
38 #include "bindings/v8/custom/V8PromiseCustom.h" 38 #include "bindings/v8/custom/V8PromiseCustom.h"
39 39
40 #include <v8.h> 40 #include <v8.h>
41 41
42 namespace WebCore { 42 namespace WebCore {
43 43
44 ScriptPromiseResolver::ScriptPromiseResolver(ExecutionContext* context) 44 ScriptPromiseResolver::ScriptPromiseResolver(ScriptState* scriptState)
45 : m_isolate(toIsolate(context)) 45 : m_scriptState(scriptState)
46 { 46 {
47 ASSERT(context); 47 v8::Isolate* isolate = m_scriptState->isolate();
48 v8::Isolate* isolate = toIsolate(context); 48 ASSERT(!m_scriptState->contextIsEmpty());
49 ASSERT(isolate->InContext()); 49 ASSERT(isolate->InContext());
50 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled()) { 50 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled()) {
51 m_resolver = ScriptValue(v8::Promise::Resolver::New(isolate), isolate); 51 m_resolver = ScriptValue(scriptState, v8::Promise::Resolver::New(isolate ));
52 } else { 52 } else {
53 v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld ::current(isolate)); 53 m_promise = ScriptPromise(scriptState, V8PromiseCustom::createPromise(m_ scriptState->context()->Global(), isolate));
54 v8::Handle<v8::Object> creationContext = v8Context.IsEmpty() ? v8::Objec t::New(isolate) : v8Context->Global();
55 m_promise = ScriptPromise(V8PromiseCustom::createPromise(creationContext , isolate), isolate);
56 } 54 }
57 } 55 }
58 56
59 ScriptPromiseResolver::ScriptPromiseResolver(v8::Isolate* isolate)
60 : m_isolate(isolate)
61 {
62 ASSERT(isolate->InContext());
63 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled()) {
64 m_resolver = ScriptValue(v8::Promise::Resolver::New(isolate), isolate);
65 } else {
66 m_promise = ScriptPromise(V8PromiseCustom::createPromise(v8::Object::New (isolate), isolate), isolate);
67 }
68 }
69
70 ScriptPromiseResolver::~ScriptPromiseResolver() 57 ScriptPromiseResolver::~ScriptPromiseResolver()
71 { 58 {
72 // We don't call "reject" here because it requires a caller 59 // We don't call "reject" here because it requires a caller
73 // to be in a v8 context. 60 // to be in a v8 context.
74 61
75 m_promise.clear(); 62 m_promise.clear();
76 m_resolver.clear(); 63 m_resolver.clear();
77 } 64 }
78 65
79 ScriptPromise ScriptPromiseResolver::promise() 66 ScriptPromise ScriptPromiseResolver::promise()
80 { 67 {
81 ASSERT(m_isolate->InContext()); 68 ASSERT(!m_scriptState->contextIsEmpty());
69 ASSERT(m_scriptState->isolate()->InContext());
82 if (!m_resolver.isEmpty()) { 70 if (!m_resolver.isEmpty()) {
83 v8::Local<v8::Promise::Resolver> v8Resolver = m_resolver.v8Value().As<v8 ::Promise::Resolver>(); 71 v8::Local<v8::Promise::Resolver> v8Resolver = m_resolver.v8Value().As<v8 ::Promise::Resolver>();
84 return ScriptPromise(v8Resolver->GetPromise(), m_isolate); 72 return ScriptPromise(m_scriptState.get(), v8Resolver->GetPromise());
85 } 73 }
86 return m_promise; 74 return m_promise;
87 } 75 }
88 76
89 PassRefPtr<ScriptPromiseResolver> ScriptPromiseResolver::create(ExecutionContext * context) 77 PassRefPtr<ScriptPromiseResolver> ScriptPromiseResolver::create(ScriptState* scr iptState)
90 { 78 {
91 ASSERT(context); 79 ASSERT(scriptState->isolate()->InContext());
92 ASSERT(toIsolate(context)->InContext()); 80 return adoptRef(new ScriptPromiseResolver(scriptState));
93 return adoptRef(new ScriptPromiseResolver(context));
94 }
95
96 PassRefPtr<ScriptPromiseResolver> ScriptPromiseResolver::create(v8::Isolate* iso late)
97 {
98 ASSERT(isolate->InContext());
99 return adoptRef(new ScriptPromiseResolver(isolate));
100 } 81 }
101 82
102 void ScriptPromiseResolver::resolve(v8::Handle<v8::Value> value) 83 void ScriptPromiseResolver::resolve(v8::Handle<v8::Value> value)
103 { 84 {
104 ASSERT(m_isolate->InContext()); 85 ASSERT(m_scriptState->isolate()->InContext());
105 if (!m_resolver.isEmpty()) { 86 if (!m_resolver.isEmpty()) {
106 m_resolver.v8Value().As<v8::Promise::Resolver>()->Resolve(value); 87 m_resolver.v8Value().As<v8::Promise::Resolver>()->Resolve(value);
107 } else if (!m_promise.isEmpty()) { 88 } else if (!m_promise.isEmpty()) {
108 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); 89 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>();
109 ASSERT(V8PromiseCustom::isPromise(promise, m_isolate)); 90 ASSERT(V8PromiseCustom::isPromise(promise, m_scriptState->isolate()));
110 V8PromiseCustom::resolve(promise, value, m_isolate); 91 V8PromiseCustom::resolve(promise, value, m_scriptState->isolate());
111 } 92 }
112 m_promise.clear(); 93 m_promise.clear();
113 m_resolver.clear(); 94 m_resolver.clear();
114 } 95 }
115 96
116 void ScriptPromiseResolver::reject(v8::Handle<v8::Value> value) 97 void ScriptPromiseResolver::reject(v8::Handle<v8::Value> value)
117 { 98 {
118 ASSERT(m_isolate->InContext()); 99 ASSERT(m_scriptState->isolate()->InContext());
119 if (!m_resolver.isEmpty()) { 100 if (!m_resolver.isEmpty()) {
120 m_resolver.v8Value().As<v8::Promise::Resolver>()->Reject(value); 101 m_resolver.v8Value().As<v8::Promise::Resolver>()->Reject(value);
121 } else if (!m_promise.isEmpty()) { 102 } else if (!m_promise.isEmpty()) {
122 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); 103 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>();
123 ASSERT(V8PromiseCustom::isPromise(promise, m_isolate)); 104 ASSERT(V8PromiseCustom::isPromise(promise, m_scriptState->isolate()));
124 V8PromiseCustom::reject(promise, value, m_isolate); 105 V8PromiseCustom::reject(promise, value, m_scriptState->isolate());
125 } 106 }
126 m_promise.clear(); 107 m_promise.clear();
127 m_resolver.clear(); 108 m_resolver.clear();
128 } 109 }
129 110
130 } // namespace WebCore 111 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698