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 |
| 33 #include "V8Future.h" |
| 34 |
| 35 // Include generated files. |
| 36 #include "V8FutureResolver.h" |
| 37 |
| 38 #include "bindings/v8/V8AnyCallback.h" |
| 39 #include "bindings/v8/V8Binding.h" |
| 40 #include "bindings/v8/V8DOMWrapper.h" |
| 41 #include "bindings/v8/V8FutureInit.h" |
| 42 #include "bindings/v8/V8Utilities.h" |
| 43 #include "core/dom/AnyCallback.h" |
| 44 #include "core/dom/Future.h" |
| 45 #include "core/dom/FutureInit.h" |
| 46 #include "core/platform/Logging.h" |
| 47 #include "wtf/RefPtr.h" |
| 48 |
| 49 #include <v8.h> |
| 50 |
| 51 namespace WebCore { |
| 52 |
| 53 v8::Handle<v8::Value> V8Future::constructorCustom(const v8::Arguments& args) |
| 54 { |
| 55 if (args.Length() < 1) |
| 56 return throwNotEnoughArgumentsError(args.GetIsolate()); |
| 57 |
| 58 LOG(Network, "V8Future::constructorCustom start"); |
| 59 |
| 60 v8::Handle<v8::Value> initArg = args[0]; |
| 61 if (!initArg->IsFunction()) |
| 62 return throwTypeError("Callback argument must be a function", args.GetIs
olate()); |
| 63 |
| 64 ScriptExecutionContext* context = getScriptExecutionContext(); |
| 65 |
| 66 RefPtr<FutureInit> init = V8FutureInit::create(v8::Handle<v8::Function>::Cas
t(initArg), context); |
| 67 |
| 68 RefPtr<Future> future = Future::createAndRunInit(init); |
| 69 |
| 70 LOG(Network, "V8Future::constructorCustom end"); |
| 71 |
| 72 // No wrap? |
| 73 return toV8(future.get(), args.Holder(), args.GetIsolate()); |
| 74 } |
| 75 |
| 76 v8::Handle<v8::Value> V8Future::thenMethodCustom(const v8::Arguments& args) |
| 77 { |
| 78 ScriptExecutionContext* context = getScriptExecutionContext(); |
| 79 |
| 80 RefPtr<AnyCallback> acceptCallback; |
| 81 if (args.Length() >= 1) { |
| 82 if (!args[0]->IsFunction()) |
| 83 return throwTypeError("acceptCallback argument must be a function",
args.GetIsolate()); |
| 84 acceptCallback = V8AnyCallback::create(v8::Handle<v8::Function>::Cast(ar
gs[0]), context); |
| 85 } |
| 86 |
| 87 RefPtr<AnyCallback> rejectCallback; |
| 88 if (args.Length() >= 2) { |
| 89 if (!args[1]->IsFunction()) |
| 90 return throwTypeError("rejectCallback argument must be a function",
args.GetIsolate()); |
| 91 rejectCallback = V8AnyCallback::create(v8::Handle<v8::Function>::Cast(ar
gs[1]), context); |
| 92 } |
| 93 |
| 94 v8::Handle<v8::Object> wrapper = args.Holder(); |
| 95 |
| 96 Future* impl = toNative(wrapper); |
| 97 |
| 98 RefPtr<Future> newFuture = impl->then(acceptCallback.release(), rejectCallba
ck.release()); |
| 99 |
| 100 return toV8(newFuture.release(), wrapper, args.GetIsolate()); |
| 101 } |
| 102 |
| 103 v8::Handle<v8::Value> V8Future::catchMethodCustom(const v8::Arguments& args) |
| 104 { |
| 105 ScriptExecutionContext* context = getScriptExecutionContext(); |
| 106 |
| 107 RefPtr<AnyCallback> rejectCallback; |
| 108 if (args.Length() >= 1) { |
| 109 if (!args[0]->IsFunction()) |
| 110 return throwTypeError("rejectCallback argument must be a function",
args.GetIsolate()); |
| 111 rejectCallback = V8AnyCallback::create(v8::Handle<v8::Function>::Cast(ar
gs[0]), context); |
| 112 } |
| 113 |
| 114 v8::Handle<v8::Object> wrapper = args.Holder(); |
| 115 |
| 116 Future* impl = toNative(wrapper); |
| 117 |
| 118 RefPtr<Future> newFuture = impl->then(0, rejectCallback.release()); |
| 119 |
| 120 return toV8(newFuture.release(), wrapper, args.GetIsolate()); |
| 121 } |
| 122 |
| 123 v8::Handle<v8::Value> V8Future::doneMethodCustom(const v8::Arguments& args) |
| 124 { |
| 125 ScriptExecutionContext* context = getScriptExecutionContext(); |
| 126 |
| 127 RefPtr<AnyCallback> acceptCallback; |
| 128 if (args.Length() >= 1) { |
| 129 if (!args[0]->IsFunction()) |
| 130 return throwTypeError("acceptCallback argument must be a function",
args.GetIsolate()); |
| 131 acceptCallback = V8AnyCallback::create(v8::Handle<v8::Function>::Cast(ar
gs[0]), context); |
| 132 } |
| 133 RefPtr<AnyCallback> rejectCallback; |
| 134 if (args.Length() >= 2) { |
| 135 if (!args[1]->IsFunction()) |
| 136 return throwTypeError("rejectCallback argument must be a function",
args.GetIsolate()); |
| 137 rejectCallback = V8AnyCallback::create(v8::Handle<v8::Function>::Cast(ar
gs[1]), context); |
| 138 } |
| 139 |
| 140 toNative(args.Holder())->done(acceptCallback, rejectCallback); |
| 141 |
| 142 return v8::Undefined(); |
| 143 } |
| 144 |
| 145 } // namespace WebCore |
OLD | NEW |