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 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "bindings/core/v8/ScriptPromise.h" | 32 #include "bindings/core/v8/ScriptPromise.h" |
33 | 33 |
| 34 #include "bindings/core/v8/ExceptionMessages.h" |
| 35 #include "bindings/core/v8/ExceptionState.h" |
34 #include "bindings/core/v8/V8Binding.h" | 36 #include "bindings/core/v8/V8Binding.h" |
| 37 #include "bindings/core/v8/V8ThrowException.h" |
35 #include "core/dom/DOMException.h" | 38 #include "core/dom/DOMException.h" |
36 | 39 |
37 #include <v8.h> | 40 #include <v8.h> |
38 | 41 |
39 namespace blink { | 42 namespace blink { |
40 | 43 |
41 namespace { | 44 namespace { |
42 | 45 |
43 struct WithScriptState { | 46 struct WithScriptState { |
44 // Used by ToV8Value<WithScriptState, ScriptState*>. | 47 // Used by ToV8Value<WithScriptState, ScriptState*>. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 resolver.reject(value); | 160 resolver.reject(value); |
158 return promise; | 161 return promise; |
159 } | 162 } |
160 | 163 |
161 ScriptPromise ScriptPromise::rejectWithDOMException(ScriptState* scriptState, Pa
ssRefPtrWillBeRawPtr<DOMException> exception) | 164 ScriptPromise ScriptPromise::rejectWithDOMException(ScriptState* scriptState, Pa
ssRefPtrWillBeRawPtr<DOMException> exception) |
162 { | 165 { |
163 ASSERT(scriptState->isolate()->InContext()); | 166 ASSERT(scriptState->isolate()->InContext()); |
164 return reject(scriptState, V8ValueTraits<PassRefPtrWillBeRawPtr<DOMException
> >::toV8Value(exception, scriptState->context()->Global(), scriptState->isolate
())); | 167 return reject(scriptState, V8ValueTraits<PassRefPtrWillBeRawPtr<DOMException
> >::toV8Value(exception, scriptState->context()->Global(), scriptState->isolate
())); |
165 } | 168 } |
166 | 169 |
| 170 ScriptPromise ScriptPromise::rejectWithTypeError(ScriptState* scriptState, const
String& message) |
| 171 { |
| 172 v8::Isolate* isolate = scriptState->isolate(); |
| 173 return reject(scriptState, V8ThrowException::createTypeError(message, isolat
e)); |
| 174 } |
| 175 |
| 176 ScriptPromise ScriptPromise::rejectWithArityTypeErrorForMethod(ScriptState* scri
ptState, const char* method, const char* type, const char* valid, unsigned provi
ded) |
| 177 { |
| 178 String message = ExceptionMessages::failedToExecute(method, type, ExceptionM
essages::invalidArity(valid, provided)); |
| 179 return rejectWithTypeError(scriptState, message); |
| 180 } |
| 181 |
| 182 ScriptPromise ScriptPromise::rejectWithArityTypeErrorForConstructor(ScriptState*
scriptState, const char* type, const char* valid, unsigned provided) |
| 183 { |
| 184 String message = ExceptionMessages::failedToConstruct(type, ExceptionMessage
s::invalidArity(valid, provided)); |
| 185 return rejectWithTypeError(scriptState, message); |
| 186 } |
| 187 |
| 188 ScriptPromise ScriptPromise::rejectWithArityTypeError(ScriptState* scriptState,
ExceptionState& exceptionState, const char* valid, unsigned provided) |
| 189 { |
| 190 exceptionState.throwTypeError(ExceptionMessages::invalidArity(valid, provide
d)); |
| 191 return exceptionState.reject(scriptState); |
| 192 } |
| 193 |
| 194 ScriptPromise ScriptPromise::rejectWithMinimumArityTypeErrorForMethod( |
| 195 ScriptState* scriptState, const char* method, const char* type, unsigned exp
ected, unsigned providedLeastNumMandatoryParams) |
| 196 { |
| 197 String message = ExceptionMessages::failedToExecute(method, type, ExceptionM
essages::notEnoughArguments(expected, providedLeastNumMandatoryParams)); |
| 198 return rejectWithTypeError(scriptState, message); |
| 199 } |
| 200 |
| 201 ScriptPromise ScriptPromise::rejectWithMinimumArityTypeErrorForConstructor( |
| 202 ScriptState* scriptState, const char* type, unsigned expected, unsigned prov
idedLeastNumMandatoryParams) |
| 203 { |
| 204 String message = ExceptionMessages::failedToConstruct(type, ExceptionMessage
s::notEnoughArguments(expected, providedLeastNumMandatoryParams)); |
| 205 return rejectWithTypeError(scriptState, message); |
| 206 } |
| 207 |
| 208 ScriptPromise ScriptPromise::rejectWithMinimumArityTypeError(ScriptState* script
State, ExceptionState& exceptionState, unsigned expected, unsigned providedLeast
NumMandatoryParams) |
| 209 { |
| 210 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(expected
, providedLeastNumMandatoryParams)); |
| 211 return exceptionState.reject(scriptState); |
| 212 } |
| 213 |
| 214 v8::Local<v8::Promise> ScriptPromise::rejectRaw(v8::Isolate* isolate, v8::Handle
<v8::Value> value) |
| 215 { |
| 216 if (value.IsEmpty()) |
| 217 return v8::Local<v8::Promise>(); |
| 218 v8::Local<v8::Promise::Resolver> resolver = v8::Promise::Resolver::New(isola
te); |
| 219 v8::Local<v8::Promise> promise = resolver->GetPromise(); |
| 220 resolver->Reject(value); |
| 221 return promise; |
| 222 } |
| 223 |
167 } // namespace blink | 224 } // namespace blink |
OLD | NEW |