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 21 matching lines...) Expand all Loading... | |
32 #include "bindings/v8/ScriptPromise.h" | 32 #include "bindings/v8/ScriptPromise.h" |
33 | 33 |
34 #include "bindings/v8/V8Binding.h" | 34 #include "bindings/v8/V8Binding.h" |
35 #include "bindings/v8/V8DOMWrapper.h" | 35 #include "bindings/v8/V8DOMWrapper.h" |
36 #include "bindings/v8/custom/V8PromiseCustom.h" | 36 #include "bindings/v8/custom/V8PromiseCustom.h" |
37 | 37 |
38 #include <v8.h> | 38 #include <v8.h> |
39 | 39 |
40 namespace WebCore { | 40 namespace WebCore { |
41 | 41 |
42 ScriptPromise::ScriptPromise(v8::Handle<v8::Value> value, v8::Isolate* isolate) | |
43 { | |
44 if (value.IsEmpty() || !V8PromiseCustom::isPromise(value, isolate)) { | |
45 m_promise = ScriptValue(v8::Handle<v8::Value>(), isolate); | |
46 V8ThrowException::throwTypeError("the given value is not a Promise", iso late); | |
47 return; | |
48 } | |
49 m_promise = ScriptValue(value, isolate); | |
50 } | |
51 | |
42 ScriptPromise ScriptPromise::then(PassOwnPtr<ScriptFunction> onFulfilled, PassOw nPtr<ScriptFunction> onRejected) | 52 ScriptPromise ScriptPromise::then(PassOwnPtr<ScriptFunction> onFulfilled, PassOw nPtr<ScriptFunction> onRejected) |
43 { | 53 { |
44 if (m_promise.hasNoValue() || !m_promise.isObject()) | 54 if (m_promise.hasNoValue() || !m_promise.isObject()) |
45 return ScriptPromise(); | 55 return ScriptPromise(); |
46 v8::Handle<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); | 56 v8::Handle<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); |
47 return ScriptPromise(V8PromiseCustom::then(promise, adoptByGarbageCollector( onFulfilled), adoptByGarbageCollector(onRejected), isolate()), isolate()); | 57 return ScriptPromise(V8PromiseCustom::then(promise, adoptByGarbageCollector( onFulfilled), adoptByGarbageCollector(onRejected), isolate()), isolate()); |
48 } | 58 } |
49 | 59 |
50 ScriptPromise::ScriptPromise(const ScriptValue& value) | 60 ScriptPromise ScriptPromise::cast(const ScriptValue& value) |
kinuko
2014/02/26 07:53:21
nit: can we match the order in .h and in .cpp? (th
yhirano
2014/02/26 09:29:57
Done.
| |
51 { | 61 { |
52 if (value.hasNoValue()) | 62 if (value.hasNoValue()) |
53 return; | 63 return ScriptPromise(); |
54 v8::Local<v8::Value> v8Value(value.v8Value()); | 64 v8::Local<v8::Value> v8Value(value.v8Value()); |
55 v8::Isolate* isolate = value.isolate(); | 65 v8::Isolate* isolate = value.isolate(); |
56 if (V8PromiseCustom::isPromise(v8Value, isolate)) { | 66 if (V8PromiseCustom::isPromise(v8Value, isolate)) { |
57 m_promise = value; | 67 return ScriptPromise(v8Value, isolate); |
58 return; | |
59 } | 68 } |
60 m_promise = ScriptValue(V8PromiseCustom::toPromise(v8Value, isolate), isolat e); | 69 return ScriptPromise(V8PromiseCustom::toPromise(v8Value, isolate), isolate); |
61 } | 70 } |
62 | 71 |
63 ScriptPromise ScriptPromise::createPending(ExecutionContext* context) | 72 ScriptPromise ScriptPromise::createPending(ExecutionContext* context) |
64 { | 73 { |
65 ASSERT(context); | 74 ASSERT(context); |
66 v8::Isolate* isolate = toIsolate(context); | 75 v8::Isolate* isolate = toIsolate(context); |
67 ASSERT(isolate->InContext()); | 76 ASSERT(isolate->InContext()); |
68 v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld::cu rrent(isolate)); | 77 v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld::cu rrent(isolate)); |
69 v8::Handle<v8::Object> creationContext = v8Context.IsEmpty() ? v8::Object::N ew(isolate) : v8Context->Global(); | 78 v8::Handle<v8::Object> creationContext = v8Context.IsEmpty() ? v8::Object::N ew(isolate) : v8Context->Global(); |
70 v8::Handle<v8::Object> promise = V8PromiseCustom::createPromise(creationCont ext, isolate); | 79 v8::Handle<v8::Object> promise = V8PromiseCustom::createPromise(creationCont ext, isolate); |
71 return ScriptPromise(promise, isolate); | 80 return ScriptPromise(promise, isolate); |
72 } | 81 } |
73 | 82 |
74 ScriptPromise ScriptPromise::createPending() | 83 ScriptPromise ScriptPromise::createPending() |
75 { | 84 { |
76 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 85 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
77 ASSERT(isolate->InContext()); | 86 ASSERT(isolate->InContext()); |
78 v8::Handle<v8::Object> promise = V8PromiseCustom::createPromise(v8::Object:: New(isolate), isolate); | 87 v8::Handle<v8::Object> promise = V8PromiseCustom::createPromise(v8::Object:: New(isolate), isolate); |
79 return ScriptPromise(promise, isolate); | 88 return ScriptPromise(promise, isolate); |
80 } | 89 } |
81 | 90 |
82 } // namespace WebCore | 91 } // namespace WebCore |
OLD | NEW |