OLD | NEW |
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 <v8.h> |
14 #include "bindings/core/v8/ExceptionState.h" | 15 #include "bindings/core/v8/ExceptionState.h" |
15 #include "bindings/core/v8/V8Binding.h" | 16 #include "bindings/core/v8/V8Binding.h" |
16 #include "core/CoreExport.h" | 17 #include "core/CoreExport.h" |
17 #include "wtf/PassRefPtr.h" | 18 #include "wtf/PassRefPtr.h" |
18 #include <v8.h> | |
19 | 19 |
20 namespace blink { | 20 namespace blink { |
21 | 21 |
22 class ScriptState; | 22 class ScriptState; |
23 class SerializedScriptValue; | 23 class SerializedScriptValue; |
24 | 24 |
25 CORE_EXPORT void v8ConstructorAttributeGetter( | 25 CORE_EXPORT void v8ConstructorAttributeGetter( |
26 v8::Local<v8::Name> propertyName, | 26 v8::Local<v8::Name> propertyName, |
27 const v8::PropertyCallbackInfo<v8::Value>&); | 27 const v8::PropertyCallbackInfo<v8::Value>&); |
28 | 28 |
29 CORE_EXPORT v8::Local<v8::Value> v8Deserialize( | 29 CORE_EXPORT v8::Local<v8::Value> v8Deserialize( |
30 v8::Isolate*, | 30 v8::Isolate*, |
31 PassRefPtr<SerializedScriptValue>); | 31 PassRefPtr<SerializedScriptValue>); |
32 | 32 |
33 // ExceptionToRejectPromiseScope converts a possible exception to a reject | 33 // ExceptionToRejectPromiseScope converts a possible exception to a reject |
34 // promise and returns the promise instead of throwing the exception. | 34 // promise and returns the promise instead of throwing the exception. |
35 // | 35 // |
36 // Promise-returning DOM operations are required to always return a promise | 36 // Promise-returning DOM operations are required to always return a promise |
37 // and to never throw an exception. | 37 // and to never throw an exception. |
38 // See also http://heycam.github.io/webidl/#es-operations | 38 // See also http://heycam.github.io/webidl/#es-operations |
39 class CORE_EXPORT ExceptionToRejectPromiseScope { | 39 class CORE_EXPORT ExceptionToRejectPromiseScope { |
40 STACK_ALLOCATED(); | 40 STACK_ALLOCATED(); |
41 | 41 |
42 public: | 42 public: |
43 ExceptionToRejectPromiseScope(const v8::FunctionCallbackInfo<v8::Value>& info, | 43 ExceptionToRejectPromiseScope(const v8::FunctionCallbackInfo<v8::Value>& info, |
44 ExceptionState& exceptionState) | 44 ExceptionState& exceptionState) |
45 : m_info(info), | 45 : m_info(info), m_exceptionState(exceptionState) {} |
46 m_exceptionState(exceptionState) {} | |
47 ~ExceptionToRejectPromiseScope() { | 46 ~ExceptionToRejectPromiseScope() { |
48 if (!m_exceptionState.hadException()) | 47 if (!m_exceptionState.hadException()) |
49 return; | 48 return; |
50 | 49 |
51 // As exceptions must always be created in the current realm, reject | 50 // As exceptions must always be created in the current realm, reject |
52 // promises must also be created in the current realm while regular promises | 51 // promises must also be created in the current realm while regular promises |
53 // are created in the relevant realm of the context object. | 52 // are created in the relevant realm of the context object. |
54 ScriptState* scriptState = ScriptState::forFunctionObject(m_info); | 53 ScriptState* scriptState = ScriptState::forFunctionObject(m_info); |
55 v8SetReturnValue(m_info, m_exceptionState.reject(scriptState).v8Value()); | 54 v8SetReturnValue(m_info, m_exceptionState.reject(scriptState).v8Value()); |
56 } | 55 } |
(...skipping 11 matching lines...) Expand all Loading... |
68 using InstallRuntimeEnabledFunction = | 67 using InstallRuntimeEnabledFunction = |
69 void (*)(v8::Isolate* isolate, | 68 void (*)(v8::Isolate* isolate, |
70 const DOMWrapperWorld& world, | 69 const DOMWrapperWorld& world, |
71 v8::Local<v8::Object> instance, | 70 v8::Local<v8::Object> instance, |
72 v8::Local<v8::Object> prototype, | 71 v8::Local<v8::Object> prototype, |
73 v8::Local<v8::Function> interface); | 72 v8::Local<v8::Function> interface); |
74 | 73 |
75 } // namespace blink | 74 } // namespace blink |
76 | 75 |
77 #endif // GeneratedCodeHelper_h | 76 #endif // GeneratedCodeHelper_h |
OLD | NEW |