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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // value may not be a Blink's wrapper object. In order to make sure of it, | 74 // value may not be a Blink's wrapper object. In order to make sure of it, |
75 // Use isWrapper function instead. | 75 // Use isWrapper function instead. |
76 CORE_EXPORT static bool HasInternalFieldsSet(v8::Local<v8::Value>); | 76 CORE_EXPORT static bool HasInternalFieldsSet(v8::Local<v8::Value>); |
77 }; | 77 }; |
78 | 78 |
79 inline void V8DOMWrapper::SetNativeInfo( | 79 inline void V8DOMWrapper::SetNativeInfo( |
80 v8::Isolate* isolate, | 80 v8::Isolate* isolate, |
81 v8::Local<v8::Object> wrapper, | 81 v8::Local<v8::Object> wrapper, |
82 const WrapperTypeInfo* wrapper_type_info, | 82 const WrapperTypeInfo* wrapper_type_info, |
83 ScriptWrappable* script_wrappable) { | 83 ScriptWrappable* script_wrappable) { |
84 ASSERT(wrapper->InternalFieldCount() >= 2); | 84 DCHECK_GE(wrapper->InternalFieldCount(), 2); |
85 ASSERT(script_wrappable); | 85 DCHECK(script_wrappable); |
86 ASSERT(wrapper_type_info); | 86 DCHECK(wrapper_type_info); |
87 int indices[] = {kV8DOMWrapperObjectIndex, kV8DOMWrapperTypeIndex}; | 87 int indices[] = {kV8DOMWrapperObjectIndex, kV8DOMWrapperTypeIndex}; |
88 void* values[] = {script_wrappable, | 88 void* values[] = {script_wrappable, |
89 const_cast<WrapperTypeInfo*>(wrapper_type_info)}; | 89 const_cast<WrapperTypeInfo*>(wrapper_type_info)}; |
90 wrapper->SetAlignedPointerInInternalFields(WTF_ARRAY_LENGTH(indices), indices, | 90 wrapper->SetAlignedPointerInInternalFields(WTF_ARRAY_LENGTH(indices), indices, |
91 values); | 91 values); |
92 auto per_isolate_data = V8PerIsolateData::From(isolate); | 92 auto per_isolate_data = V8PerIsolateData::From(isolate); |
93 // We notify ScriptWrappableVisitor about the new wrapper association, | 93 // We notify ScriptWrappableVisitor about the new wrapper association, |
94 // so the visitor can make sure to trace the association (in case it is | 94 // so the visitor can make sure to trace the association (in case it is |
95 // currently tracing). Because of some optimizations, V8 will not | 95 // currently tracing). Because of some optimizations, V8 will not |
96 // necessarily detect wrappers created during its incremental marking. | 96 // necessarily detect wrappers created during its incremental marking. |
(...skipping 11 matching lines...) Expand all Loading... |
108 } | 108 } |
109 | 109 |
110 inline v8::Local<v8::Object> V8DOMWrapper::AssociateObjectWithWrapper( | 110 inline v8::Local<v8::Object> V8DOMWrapper::AssociateObjectWithWrapper( |
111 v8::Isolate* isolate, | 111 v8::Isolate* isolate, |
112 ScriptWrappable* impl, | 112 ScriptWrappable* impl, |
113 const WrapperTypeInfo* wrapper_type_info, | 113 const WrapperTypeInfo* wrapper_type_info, |
114 v8::Local<v8::Object> wrapper) { | 114 v8::Local<v8::Object> wrapper) { |
115 if (DOMDataStore::SetWrapper(isolate, impl, wrapper_type_info, wrapper)) { | 115 if (DOMDataStore::SetWrapper(isolate, impl, wrapper_type_info, wrapper)) { |
116 wrapper_type_info->WrapperCreated(); | 116 wrapper_type_info->WrapperCreated(); |
117 SetNativeInfo(isolate, wrapper, wrapper_type_info, impl); | 117 SetNativeInfo(isolate, wrapper, wrapper_type_info, impl); |
118 ASSERT(HasInternalFieldsSet(wrapper)); | 118 DCHECK(HasInternalFieldsSet(wrapper)); |
119 } | 119 } |
120 SECURITY_CHECK(ToScriptWrappable(wrapper) == impl); | 120 SECURITY_CHECK(ToScriptWrappable(wrapper) == impl); |
121 return wrapper; | 121 return wrapper; |
122 } | 122 } |
123 | 123 |
124 class V8WrapperInstantiationScope { | 124 class V8WrapperInstantiationScope { |
125 STACK_ALLOCATED(); | 125 STACK_ALLOCATED(); |
126 | 126 |
127 public: | 127 public: |
128 V8WrapperInstantiationScope(v8::Local<v8::Object> creation_context, | 128 V8WrapperInstantiationScope(v8::Local<v8::Object> creation_context, |
129 v8::Isolate* isolate, | 129 v8::Isolate* isolate, |
130 const WrapperTypeInfo* type) | 130 const WrapperTypeInfo* type) |
131 : did_enter_context_(false), | 131 : did_enter_context_(false), |
132 context_(isolate->GetCurrentContext()), | 132 context_(isolate->GetCurrentContext()), |
133 try_catch_(isolate), | 133 try_catch_(isolate), |
134 type_(type), | 134 type_(type), |
135 access_check_failed_(false) { | 135 access_check_failed_(false) { |
136 // creationContext should not be empty. Because if we have an | 136 // creationContext should not be empty. Because if we have an |
137 // empty creationContext, we will end up creating | 137 // empty creationContext, we will end up creating |
138 // a new object in the context currently entered. This is wrong. | 138 // a new object in the context currently entered. This is wrong. |
139 RELEASE_ASSERT(!creation_context.IsEmpty()); | 139 CHECK(!creation_context.IsEmpty()); |
140 v8::Local<v8::Context> context_for_wrapper = | 140 v8::Local<v8::Context> context_for_wrapper = |
141 creation_context->CreationContext(); | 141 creation_context->CreationContext(); |
142 | 142 |
143 // For performance, we enter the context only if the currently running | 143 // For performance, we enter the context only if the currently running |
144 // context is different from the context that we are about to enter. | 144 // context is different from the context that we are about to enter. |
145 if (context_for_wrapper == context_) | 145 if (context_for_wrapper == context_) |
146 return; | 146 return; |
147 | 147 |
148 context_ = context_for_wrapper; | 148 context_ = context_for_wrapper; |
149 | 149 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 bool did_enter_context_; | 186 bool did_enter_context_; |
187 v8::Local<v8::Context> context_; | 187 v8::Local<v8::Context> context_; |
188 v8::TryCatch try_catch_; | 188 v8::TryCatch try_catch_; |
189 const WrapperTypeInfo* type_; | 189 const WrapperTypeInfo* type_; |
190 bool access_check_failed_; | 190 bool access_check_failed_; |
191 }; | 191 }; |
192 | 192 |
193 } // namespace blink | 193 } // namespace blink |
194 | 194 |
195 #endif // V8DOMWrapper_h | 195 #endif // V8DOMWrapper_h |
OLD | NEW |