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

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

Issue 2301993002: binding: Introduces ExceptionToPromiseScope. (Closed)
Patch Set: Removed throwMinimumArityError family. 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 // ExceptionToPromiseScope converts a possible exception to a reject promise
30 // and returns the promise instead of throwing the exception.
31 //
32 // Promise-returning DOM operations are required to always return a promise
33 // and to never throw an exception.
34 // See also http://heycam.github.io/webidl/#es-operations
35 class CORE_EXPORT ExceptionToPromiseScope {
peria 2016/09/09 02:15:24 I prefer to contain 'Reject' in this name.
36 STACK_ALLOCATED();
37 public:
38 ExceptionToPromiseScope(const v8::FunctionCallbackInfo<v8::Value>& info, Scr iptState* scriptState, ExceptionState& exceptionState)
haraken 2016/09/09 02:01:25 ExceptionToPromiseRejectionScope ?
39 : m_info(info)
40 , m_scriptState(scriptState)
41 , m_exceptionState(exceptionState) { }
42 ~ExceptionToPromiseScope()
43 {
44 if (!m_exceptionState.hadException())
45 return;
46
47 v8SetReturnValue(m_info, m_exceptionState.reject(m_scriptState).v8Value( ));
48 }
49
50 private:
51 const v8::FunctionCallbackInfo<v8::Value>& m_info;
52 ScriptState* m_scriptState;
53 ExceptionState& m_exceptionState;
54 };
55
26 } // namespace blink 56 } // namespace blink
27 57
28 #endif // GeneratedCodeHelper_h 58 #endif // GeneratedCodeHelper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698