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); | |
haraken
2016/06/08 08:56:07
Add a comment about what this is doing.
haraken
2016/06/08 08:56:07
I guess this will regress performance of wrapper c
| |
77 perIsolateData->scriptWrappableVisitor() | |
78 ->RegisterV8Reference(std::make_pair( | |
79 const_cast<WrapperTypeInfo*>(wrapperTypeInfo), scriptWrappable)) ; | |
80 } | |
75 } | 81 } |
76 | 82 |
77 inline v8::Local<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isolat e* isolate, ScriptWrappable* impl, const WrapperTypeInfo* wrapperTypeInfo, v8::L ocal<v8::Object> wrapper) | 83 inline v8::Local<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isolat e* isolate, ScriptWrappable* impl, const WrapperTypeInfo* wrapperTypeInfo, v8::L ocal<v8::Object> wrapper) |
78 { | 84 { |
79 if (DOMDataStore::setWrapper(isolate, impl, wrapperTypeInfo, wrapper)) { | 85 if (DOMDataStore::setWrapper(isolate, impl, wrapperTypeInfo, wrapper)) { |
80 wrapperTypeInfo->wrapperCreated(); | 86 wrapperTypeInfo->wrapperCreated(); |
81 setNativeInfo(wrapper, wrapperTypeInfo, impl); | 87 setNativeInfo(isolate, wrapper, wrapperTypeInfo, impl); |
82 ASSERT(hasInternalFieldsSet(wrapper)); | 88 ASSERT(hasInternalFieldsSet(wrapper)); |
83 } | 89 } |
84 SECURITY_CHECK(toScriptWrappable(wrapper) == impl); | 90 SECURITY_CHECK(toScriptWrappable(wrapper) == impl); |
85 return wrapper; | 91 return wrapper; |
86 } | 92 } |
87 | 93 |
88 inline v8::Local<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isolat e* isolate, Node* node, const WrapperTypeInfo* wrapperTypeInfo, v8::Local<v8::Ob ject> wrapper) | 94 inline v8::Local<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isolat e* isolate, Node* node, const WrapperTypeInfo* wrapperTypeInfo, v8::Local<v8::Ob ject> wrapper) |
89 { | 95 { |
90 if (DOMDataStore::setWrapper(isolate, node, wrapperTypeInfo, wrapper)) { | 96 if (DOMDataStore::setWrapper(isolate, node, wrapperTypeInfo, wrapper)) { |
91 wrapperTypeInfo->wrapperCreated(); | 97 wrapperTypeInfo->wrapperCreated(); |
92 setNativeInfo(wrapper, wrapperTypeInfo, ScriptWrappable::fromNode(node)) ; | 98 setNativeInfo(isolate, wrapper, wrapperTypeInfo, ScriptWrappable::fromNo de(node)); |
93 ASSERT(hasInternalFieldsSet(wrapper)); | 99 ASSERT(hasInternalFieldsSet(wrapper)); |
94 } | 100 } |
95 SECURITY_CHECK(toScriptWrappable(wrapper) == ScriptWrappable::fromNode(node) ); | 101 SECURITY_CHECK(toScriptWrappable(wrapper) == ScriptWrappable::fromNode(node) ); |
96 return wrapper; | 102 return wrapper; |
97 } | 103 } |
98 | 104 |
99 class V8WrapperInstantiationScope { | 105 class V8WrapperInstantiationScope { |
100 STACK_ALLOCATED(); | 106 STACK_ALLOCATED(); |
101 public: | 107 public: |
102 V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext, v8::Isola te* isolate, bool withSecurityCheck) | 108 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 | 156 |
151 bool m_didEnterContext; | 157 bool m_didEnterContext; |
152 v8::Local<v8::Context> m_context; | 158 v8::Local<v8::Context> m_context; |
153 v8::TryCatch m_tryCatch; | 159 v8::TryCatch m_tryCatch; |
154 bool m_convertExceptions; | 160 bool m_convertExceptions; |
155 }; | 161 }; |
156 | 162 |
157 } // namespace blink | 163 } // namespace blink |
158 | 164 |
159 #endif // V8DOMWrapper_h | 165 #endif // V8DOMWrapper_h |
OLD | NEW |