OLD | NEW |
---|---|
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 Loading... | |
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()); |
yhirano
2014/05/09 06:24:57
Please keep the InContext assertion.
haraken
2014/05/09 07:37:25
Done.
| |
49 ASSERT(isolate->InContext()); | |
50 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled()) { | 49 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled()) { |
51 m_resolver = ScriptValue(v8::Promise::Resolver::New(isolate), isolate); | 50 m_resolver = ScriptValue(scriptState, v8::Promise::Resolver::New(isolate )); |
52 } else { | 51 } else { |
53 v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld ::current(isolate)); | 52 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 } | 53 } |
57 } | 54 } |
58 | 55 |
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() | 56 ScriptPromiseResolver::~ScriptPromiseResolver() |
71 { | 57 { |
72 // We don't call "reject" here because it requires a caller | 58 // We don't call "reject" here because it requires a caller |
73 // to be in a v8 context. | 59 // to be in a v8 context. |
74 | 60 |
75 m_promise.clear(); | 61 m_promise.clear(); |
76 m_resolver.clear(); | 62 m_resolver.clear(); |
77 } | 63 } |
78 | 64 |
79 ScriptPromise ScriptPromiseResolver::promise() | 65 ScriptPromise ScriptPromiseResolver::promise() |
80 { | 66 { |
81 ASSERT(m_isolate->InContext()); | 67 ASSERT(!m_scriptState->contextIsEmpty()); |
yhirano
2014/05/09 06:24:57
ditto
haraken
2014/05/09 07:37:25
Done.
haraken
2014/05/09 07:37:25
Done.
| |
82 if (!m_resolver.isEmpty()) { | 68 if (!m_resolver.isEmpty()) { |
83 v8::Local<v8::Promise::Resolver> v8Resolver = m_resolver.v8Value().As<v8 ::Promise::Resolver>(); | 69 v8::Local<v8::Promise::Resolver> v8Resolver = m_resolver.v8Value().As<v8 ::Promise::Resolver>(); |
84 return ScriptPromise(v8Resolver->GetPromise(), m_isolate); | 70 return ScriptPromise(m_scriptState.get(), v8Resolver->GetPromise()); |
85 } | 71 } |
86 return m_promise; | 72 return m_promise; |
87 } | 73 } |
88 | 74 |
89 PassRefPtr<ScriptPromiseResolver> ScriptPromiseResolver::create(ExecutionContext * context) | 75 PassRefPtr<ScriptPromiseResolver> ScriptPromiseResolver::create(ScriptState* scr iptState) |
90 { | 76 { |
91 ASSERT(context); | 77 ASSERT(scriptState->isolate()->InContext()); |
92 ASSERT(toIsolate(context)->InContext()); | 78 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 } | 79 } |
101 | 80 |
102 void ScriptPromiseResolver::resolve(v8::Handle<v8::Value> value) | 81 void ScriptPromiseResolver::resolve(v8::Handle<v8::Value> value) |
103 { | 82 { |
104 ASSERT(m_isolate->InContext()); | 83 ASSERT(m_scriptState->isolate()->InContext()); |
105 if (!m_resolver.isEmpty()) { | 84 if (!m_resolver.isEmpty()) { |
106 m_resolver.v8Value().As<v8::Promise::Resolver>()->Resolve(value); | 85 m_resolver.v8Value().As<v8::Promise::Resolver>()->Resolve(value); |
107 } else if (!m_promise.isEmpty()) { | 86 } else if (!m_promise.isEmpty()) { |
108 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); | 87 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); |
109 ASSERT(V8PromiseCustom::isPromise(promise, m_isolate)); | 88 ASSERT(V8PromiseCustom::isPromise(promise, m_scriptState->isolate())); |
110 V8PromiseCustom::resolve(promise, value, m_isolate); | 89 V8PromiseCustom::resolve(promise, value, m_scriptState->isolate()); |
111 } | 90 } |
112 m_promise.clear(); | 91 m_promise.clear(); |
113 m_resolver.clear(); | 92 m_resolver.clear(); |
114 } | 93 } |
115 | 94 |
116 void ScriptPromiseResolver::reject(v8::Handle<v8::Value> value) | 95 void ScriptPromiseResolver::reject(v8::Handle<v8::Value> value) |
117 { | 96 { |
118 ASSERT(m_isolate->InContext()); | 97 ASSERT(m_scriptState->isolate()->InContext()); |
119 if (!m_resolver.isEmpty()) { | 98 if (!m_resolver.isEmpty()) { |
120 m_resolver.v8Value().As<v8::Promise::Resolver>()->Reject(value); | 99 m_resolver.v8Value().As<v8::Promise::Resolver>()->Reject(value); |
121 } else if (!m_promise.isEmpty()) { | 100 } else if (!m_promise.isEmpty()) { |
122 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); | 101 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); |
123 ASSERT(V8PromiseCustom::isPromise(promise, m_isolate)); | 102 ASSERT(V8PromiseCustom::isPromise(promise, m_scriptState->isolate())); |
124 V8PromiseCustom::reject(promise, value, m_isolate); | 103 V8PromiseCustom::reject(promise, value, m_scriptState->isolate()); |
125 } | 104 } |
126 m_promise.clear(); | 105 m_promise.clear(); |
127 m_resolver.clear(); | 106 m_resolver.clear(); |
128 } | 107 } |
129 | 108 |
130 } // namespace WebCore | 109 } // namespace WebCore |
OLD | NEW |