OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 public: | 50 public: |
51 static v8::Local<v8::Object> createWrapper(v8::Isolate*, v8::Local<v8::Objec
t> creationContext, const WrapperTypeInfo*); | 51 static v8::Local<v8::Object> createWrapper(v8::Isolate*, v8::Local<v8::Objec
t> creationContext, const WrapperTypeInfo*); |
52 static bool isWrapper(v8::Isolate*, v8::Local<v8::Value>); | 52 static bool isWrapper(v8::Isolate*, v8::Local<v8::Value>); |
53 | 53 |
54 // Associates the given ScriptWrappable with the given |wrapper| if the | 54 // Associates the given ScriptWrappable with the given |wrapper| if the |
55 // ScriptWrappable is not yet associated with any wrapper. Returns the | 55 // ScriptWrappable is not yet associated with any wrapper. Returns the |
56 // wrapper already associated or |wrapper| if not yet associated. | 56 // wrapper already associated or |wrapper| if not yet associated. |
57 // The caller should always use the returned value rather than |wrapper|. | 57 // The caller should always use the returned value rather than |wrapper|. |
58 static v8::Local<v8::Object> associateObjectWithWrapper(v8::Isolate*, Script
Wrappable*, const WrapperTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_R
ETURN; | 58 static v8::Local<v8::Object> associateObjectWithWrapper(v8::Isolate*, Script
Wrappable*, const WrapperTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_R
ETURN; |
59 static v8::Local<v8::Object> associateObjectWithWrapper(v8::Isolate*, Node*,
const WrapperTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_RETURN; | 59 static v8::Local<v8::Object> associateObjectWithWrapper(v8::Isolate*, Node*,
const WrapperTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_RETURN; |
60 static void setNativeInfo(v8::Local<v8::Object>, const WrapperTypeInfo*, Scr
iptWrappable*); | 60 static void setNativeInfo(v8::Isolate*, v8::Local<v8::Object>, const Wrapper
TypeInfo*, ScriptWrappable*); |
61 // hasInternalFieldsSet only checks if the value has the internal fields for | 61 // hasInternalFieldsSet only checks if the value has the internal fields for |
62 // wrapper obejct and type, and does not check if it's valid or not. The | 62 // wrapper obejct and type, and does not check if it's valid or not. The |
63 // value may not be a Blink's wrapper object. In order to make sure of it, | 63 // value may not be a Blink's wrapper object. In order to make sure of it, |
64 // Use isWrapper function instead. | 64 // Use isWrapper function instead. |
65 CORE_EXPORT static bool hasInternalFieldsSet(v8::Local<v8::Value>); | 65 CORE_EXPORT static bool hasInternalFieldsSet(v8::Local<v8::Value>); |
66 }; | 66 }; |
67 | 67 |
68 inline void V8DOMWrapper::setNativeInfo(v8::Local<v8::Object> wrapper, const Wra
pperTypeInfo* wrapperTypeInfo, ScriptWrappable* scriptWrappable) | 68 inline void V8DOMWrapper::setNativeInfo(v8::Isolate* isolate, v8::Local<v8::Obje
ct> wrapper, const WrapperTypeInfo* wrapperTypeInfo, ScriptWrappable* scriptWrap
pable) |
69 { | 69 { |
70 ASSERT(wrapper->InternalFieldCount() >= 2); | 70 ASSERT(wrapper->InternalFieldCount() >= 2); |
71 ASSERT(scriptWrappable); | 71 ASSERT(scriptWrappable); |
72 ASSERT(wrapperTypeInfo); | 72 ASSERT(wrapperTypeInfo); |
73 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, scriptWra
ppable); | 73 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, scriptWra
ppable); |
74 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); | 74 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); |
| 75 if (RuntimeEnabledFeatures::traceWrappablesEnabled()) { |
| 76 auto perIsolateData = V8PerIsolateData::from(isolate); |
| 77 // We notify ScriptWrappableVisitor about new wrapper association, so he |
| 78 // can make sure to trace it (in case it is currently tracing). |
| 79 // Because of some optimizations, V8 will not necessarily detect |
| 80 // wrappers created during its incremental marking. |
| 81 perIsolateData->scriptWrappableVisitor() |
| 82 ->RegisterV8Reference(std::make_pair( |
| 83 const_cast<WrapperTypeInfo*>(wrapperTypeInfo), scriptWrappable))
; |
| 84 } |
75 } | 85 } |
76 | 86 |
77 inline v8::Local<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isolat
e* isolate, ScriptWrappable* impl, const WrapperTypeInfo* wrapperTypeInfo, v8::L
ocal<v8::Object> wrapper) | 87 inline v8::Local<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isolat
e* isolate, ScriptWrappable* impl, const WrapperTypeInfo* wrapperTypeInfo, v8::L
ocal<v8::Object> wrapper) |
78 { | 88 { |
79 if (DOMDataStore::setWrapper(isolate, impl, wrapperTypeInfo, wrapper)) { | 89 if (DOMDataStore::setWrapper(isolate, impl, wrapperTypeInfo, wrapper)) { |
80 wrapperTypeInfo->wrapperCreated(); | 90 wrapperTypeInfo->wrapperCreated(); |
81 setNativeInfo(wrapper, wrapperTypeInfo, impl); | 91 setNativeInfo(isolate, wrapper, wrapperTypeInfo, impl); |
82 ASSERT(hasInternalFieldsSet(wrapper)); | 92 ASSERT(hasInternalFieldsSet(wrapper)); |
83 } | 93 } |
84 SECURITY_CHECK(toScriptWrappable(wrapper) == impl); | 94 SECURITY_CHECK(toScriptWrappable(wrapper) == impl); |
85 return wrapper; | 95 return wrapper; |
86 } | 96 } |
87 | 97 |
88 inline v8::Local<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isolat
e* isolate, Node* node, const WrapperTypeInfo* wrapperTypeInfo, v8::Local<v8::Ob
ject> wrapper) | 98 inline v8::Local<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isolat
e* isolate, Node* node, const WrapperTypeInfo* wrapperTypeInfo, v8::Local<v8::Ob
ject> wrapper) |
89 { | 99 { |
90 if (DOMDataStore::setWrapper(isolate, node, wrapperTypeInfo, wrapper)) { | 100 if (DOMDataStore::setWrapper(isolate, node, wrapperTypeInfo, wrapper)) { |
91 wrapperTypeInfo->wrapperCreated(); | 101 wrapperTypeInfo->wrapperCreated(); |
92 setNativeInfo(wrapper, wrapperTypeInfo, ScriptWrappable::fromNode(node))
; | 102 setNativeInfo(isolate, wrapper, wrapperTypeInfo, ScriptWrappable::fromNo
de(node)); |
93 ASSERT(hasInternalFieldsSet(wrapper)); | 103 ASSERT(hasInternalFieldsSet(wrapper)); |
94 } | 104 } |
95 SECURITY_CHECK(toScriptWrappable(wrapper) == ScriptWrappable::fromNode(node)
); | 105 SECURITY_CHECK(toScriptWrappable(wrapper) == ScriptWrappable::fromNode(node)
); |
96 return wrapper; | 106 return wrapper; |
97 } | 107 } |
98 | 108 |
99 class V8WrapperInstantiationScope { | 109 class V8WrapperInstantiationScope { |
100 STACK_ALLOCATED(); | 110 STACK_ALLOCATED(); |
101 public: | 111 public: |
102 V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext, v8::Isola
te* isolate, bool withSecurityCheck) | 112 V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext, v8::Isola
te* isolate, bool withSecurityCheck) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 160 |
151 bool m_didEnterContext; | 161 bool m_didEnterContext; |
152 v8::Local<v8::Context> m_context; | 162 v8::Local<v8::Context> m_context; |
153 v8::TryCatch m_tryCatch; | 163 v8::TryCatch m_tryCatch; |
154 bool m_convertExceptions; | 164 bool m_convertExceptions; |
155 }; | 165 }; |
156 | 166 |
157 } // namespace blink | 167 } // namespace blink |
158 | 168 |
159 #endif // V8DOMWrapper_h | 169 #endif // V8DOMWrapper_h |
OLD | NEW |