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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 resolver.reject(value); | 160 resolver.reject(value); |
161 return promise; | 161 return promise; |
162 } | 162 } |
163 | 163 |
164 ScriptPromise ScriptPromise::rejectWithDOMException(ScriptState* scriptState, Pa
ssRefPtrWillBeRawPtr<DOMException> exception) | 164 ScriptPromise ScriptPromise::rejectWithDOMException(ScriptState* scriptState, Pa
ssRefPtrWillBeRawPtr<DOMException> exception) |
165 { | 165 { |
166 ASSERT(scriptState->isolate()->InContext()); | 166 ASSERT(scriptState->isolate()->InContext()); |
167 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
())); |
168 } | 168 } |
169 | 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) | 170 v8::Local<v8::Promise> ScriptPromise::rejectRaw(v8::Isolate* isolate, v8::Handle
<v8::Value> value) |
215 { | 171 { |
216 if (value.IsEmpty()) | 172 if (value.IsEmpty()) |
217 return v8::Local<v8::Promise>(); | 173 return v8::Local<v8::Promise>(); |
218 v8::Local<v8::Promise::Resolver> resolver = v8::Promise::Resolver::New(isola
te); | 174 v8::Local<v8::Promise::Resolver> resolver = v8::Promise::Resolver::New(isola
te); |
219 v8::Local<v8::Promise> promise = resolver->GetPromise(); | 175 v8::Local<v8::Promise> promise = resolver->GetPromise(); |
220 resolver->Reject(value); | 176 resolver->Reject(value); |
221 return promise; | 177 return promise; |
222 } | 178 } |
223 | 179 |
224 } // namespace blink | 180 } // namespace blink |
OLD | NEW |