Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "bindings/v8/custom/V8PromiseCustom.h" | |
| 33 | |
| 34 #include "V8Promise.h" | |
| 35 #include "V8PromiseResolver.h" | |
| 36 #include "bindings/v8/V8Binding.h" | |
| 37 #include "bindings/v8/V8ScriptRunner.h" | |
| 38 #include "bindings/v8/WrapperTypeInfo.h" | |
| 39 #include <v8.h> | |
| 40 | |
| 41 namespace WebCore { | |
| 42 | |
| 43 void V8Promise::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& arg s) | |
| 44 { | |
| 45 args.GetReturnValue().Set(v8::Local<v8::Value>()); | |
|
abarth-chromium
2013/06/21 05:38:46
There isn't a SetReturnValue function?
yhirano
2013/06/21 09:36:53
Thanks, done.
| |
| 46 v8::Isolate* isolate = args.GetIsolate(); | |
| 47 if (args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsFunction()) { | |
|
haraken
2013/06/21 05:47:58
This should be 'args.Length() < 1'.
yhirano
2013/06/21 09:36:53
Done.
| |
| 48 throwTypeError("Promise constructor takes exact one function argument", isolate); | |
| 49 return; | |
| 50 } | |
| 51 v8::Handle<v8::Function> init = args[0].As<v8::Function>(); | |
| 52 v8::Local<v8::ObjectTemplate> associatedTemplate = v8::ObjectTemplate::New() ; | |
|
abarth-chromium
2013/06/21 05:38:46
Normally we create the object template in V8PerIso
yhirano
2013/06/21 09:36:53
We can attach FunctionTemplate data to V8PerIsolat
| |
| 53 associatedTemplate->SetInternalFieldCount(V8PromiseCustom::AssociatedInterna lFieldCount); | |
| 54 v8::Local<v8::Object> associated = associatedTemplate->NewInstance(); | |
| 55 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(args.Holder(), & V8Promise::info, 0, isolate); | |
| 56 v8::Local<v8::Object> promiseResolver = V8DOMWrapper::createWrapper(args.Hol der(), &V8PromiseResolver::info, 0, isolate); | |
|
haraken
2013/06/21 05:47:58
Don't you need to store a C++ object pointer to th
abarth-chromium
2013/06/21 05:58:53
The "associated" object isn't a wrapper. It's jus
yhirano
2013/06/21 09:36:53
No, instead, we set a JavaScript object as an inte
| |
| 57 | |
| 58 associated->SetInternalField(V8PromiseCustom::AssociatedStatusIndex, v8::Num berObject::New(V8PromiseCustom::Pending)); | |
|
abarth-chromium
2013/06/21 05:38:46
These plain numbers we can keep on the CPP side.
| |
| 59 associated->SetInternalField(V8PromiseCustom::AssociatedResultIndex, v8::Und efined()); | |
| 60 associated->SetInternalField(V8PromiseCustom::AssociatedFulfillCallbackIndex , v8::Array::New()); | |
| 61 associated->SetInternalField(V8PromiseCustom::AssociatedRejectCallbackIndex, v8::Array::New()); | |
| 62 | |
| 63 promise->SetInternalField(v8DOMWrapperObjectIndex, associated); | |
| 64 promiseResolver->SetInternalField(v8DOMWrapperObjectIndex, associated); | |
|
abarth-chromium
2013/06/21 05:38:46
These two object share the same associated storage
yhirano
2013/06/21 09:36:53
Hmm...
There is "state" property in the spec (I ca
| |
| 65 | |
| 66 v8::Handle<v8::Value> argv[] = { | |
| 67 promiseResolver, | |
| 68 }; | |
| 69 v8::TryCatch trycatch; | |
| 70 if (init->Call(promise, sizeof(argv) / sizeof(argv[0]), argv).IsEmpty()) { | |
|
abarth-chromium
2013/06/21 05:38:46
WTF_ARRAY_LENGTH(argv)
haraken
2013/06/21 05:47:58
You can use V8ScriptRunner::callFunction().
abarth-chromium
2013/06/21 05:58:53
Ah, sorry I missed that!
yhirano
2013/06/21 09:36:53
Done.
| |
| 71 // FIXME: An exception is thrown. Reject the promise. | |
| 72 } | |
| 73 args.GetReturnValue().Set(promise); | |
| 74 return; | |
| 75 } | |
| 76 | |
| 77 } // namespace WebCore | |
| OLD | NEW |