Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/GeneratedCodeHelper.h

Issue 2301993002: binding: Introduces ExceptionToPromiseScope. (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file is for functions that are used only by generated code. 5 // This file is for functions that are used only by generated code.
6 // CAUTION: 6 // CAUTION:
7 // All functions defined in this file should be used by generated code only. 7 // All functions defined in this file should be used by generated code only.
8 // If you want to use them from hand-written code, please find appropriate 8 // If you want to use them from hand-written code, please find appropriate
9 // location and move them to that location. 9 // location and move them to that location.
10 10
11 #ifndef GeneratedCodeHelper_h 11 #ifndef GeneratedCodeHelper_h
12 #define GeneratedCodeHelper_h 12 #define GeneratedCodeHelper_h
13 13
14 #include "bindings/core/v8/ExceptionState.h"
15 #include "bindings/core/v8/V8Binding.h"
14 #include "core/CoreExport.h" 16 #include "core/CoreExport.h"
15 #include "wtf/PassRefPtr.h" 17 #include "wtf/PassRefPtr.h"
16 #include <v8.h> 18 #include <v8.h>
17 19
18 namespace blink { 20 namespace blink {
19 21
22 class ScriptState;
20 class SerializedScriptValue; 23 class SerializedScriptValue;
21 24
22 CORE_EXPORT void v8ConstructorAttributeGetter(v8::Local<v8::Name> propertyName, const v8::PropertyCallbackInfo<v8::Value>&); 25 CORE_EXPORT void v8ConstructorAttributeGetter(v8::Local<v8::Name> propertyName, const v8::PropertyCallbackInfo<v8::Value>&);
23 26
24 CORE_EXPORT v8::Local<v8::Value> v8Deserialize(v8::Isolate*, PassRefPtr<Serializ edScriptValue>); 27 CORE_EXPORT v8::Local<v8::Value> v8Deserialize(v8::Isolate*, PassRefPtr<Serializ edScriptValue>);
25 28
29 // Throws an arity error of type TypeError.
30 CORE_EXPORT void throwMinimumArityError(ExceptionState&, unsigned expected, unsi gned actual);
31 CORE_EXPORT void throwInvalidArityError(ExceptionState&, const char* validRange, unsigned actual);
32 CORE_EXPORT void throwMinimumArityErrorForMethod(v8::Isolate*, const char* inter face, const char* method, unsigned expected, unsigned actual);
33 CORE_EXPORT void throwMinimumArityErrorForConstructor(v8::Isolate*, const char* interface, unsigned expected, unsigned actual);
34
35 // ExceptionToPromiseScope converts a possible exception to a reject promise
36 // and returns the promise instead of throwing the exception.
37 //
38 // Promise-returning DOM operations are required to always return a promise
39 // and to never throw an exception.
40 // See also http://heycam.github.io/webidl/#es-operations
41 class CORE_EXPORT ExceptionToPromiseScope {
haraken 2016/09/02 16:24:13 I still don't understand what GeneratedCodeHelper
Yuki 2016/09/05 07:19:25 I don't expect that this will be used in such a ma
haraken 2016/09/05 08:24:22 I'm confused... Note that the logic ExceptionToPr
42 STACK_ALLOCATED();
43 public:
44 ExceptionToPromiseScope(const v8::FunctionCallbackInfo<v8::Value>& info, Scr iptState* scriptState, ExceptionState& exceptionState)
haraken 2016/09/02 16:24:13 Would it make more sense to introduce another cons
Yuki 2016/09/05 07:19:25 I don't think so. ExceptionToPromiseScope depends
haraken 2016/09/05 08:24:22 As I mentioned above, this functionality is implem
45 : m_info(info)
46 , m_scriptState(scriptState)
47 , m_exceptionState(exceptionState) { }
48 ~ExceptionToPromiseScope()
49 {
50 if (!m_exceptionState.hadException())
51 return;
52
53 v8SetReturnValue(m_info, m_exceptionState.reject(m_scriptState).v8Value( ));
54 }
55
56 private:
57 const v8::FunctionCallbackInfo<v8::Value>& m_info;
58 ScriptState* m_scriptState;
59 ExceptionState& m_exceptionState;
60 };
61
26 } // namespace blink 62 } // namespace blink
27 63
28 #endif // GeneratedCodeHelper_h 64 #endif // GeneratedCodeHelper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698