OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project 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 #include "src/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 true) | 144 true) |
145 | 145 |
146 #define PREPARE_FOR_EXECUTION_PRIMITIVE(context, class_name, function_name, T) \ | 146 #define PREPARE_FOR_EXECUTION_PRIMITIVE(context, class_name, function_name, T) \ |
147 PREPARE_FOR_EXECUTION_WITH_CONTEXT(context, class_name, function_name, \ | 147 PREPARE_FOR_EXECUTION_WITH_CONTEXT(context, class_name, function_name, \ |
148 Nothing<T>(), i::HandleScope, false) | 148 Nothing<T>(), i::HandleScope, false) |
149 | 149 |
150 #define PREPARE_FOR_EXECUTION_BOOL(context, class_name, function_name) \ | 150 #define PREPARE_FOR_EXECUTION_BOOL(context, class_name, function_name) \ |
151 PREPARE_FOR_EXECUTION_WITH_CONTEXT(context, class_name, function_name, \ | 151 PREPARE_FOR_EXECUTION_WITH_CONTEXT(context, class_name, function_name, \ |
152 false, i::HandleScope, false) | 152 false, i::HandleScope, false) |
153 | 153 |
| 154 #define ENTER_V8_FOR_NEW_CONTEXT(isolate) \ |
| 155 i::VMState<v8::OTHER> __state__((isolate)); \ |
| 156 i::DisallowExceptions __no_exceptions__((isolate)) |
| 157 |
154 #define EXCEPTION_BAILOUT_CHECK_SCOPED(isolate, value) \ | 158 #define EXCEPTION_BAILOUT_CHECK_SCOPED(isolate, value) \ |
155 do { \ | 159 do { \ |
156 if (has_pending_exception) { \ | 160 if (has_pending_exception) { \ |
157 call_depth_scope.Escape(); \ | 161 call_depth_scope.Escape(); \ |
158 return value; \ | 162 return value; \ |
159 } \ | 163 } \ |
160 } while (false) | 164 } while (false) |
161 | 165 |
162 | 166 |
163 #define RETURN_ON_FAILED_EXECUTION(T) \ | 167 #define RETURN_ON_FAILED_EXECUTION(T) \ |
(...skipping 6032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6196 }; | 6200 }; |
6197 | 6201 |
6198 template <typename ObjectType> | 6202 template <typename ObjectType> |
6199 static i::Handle<ObjectType> CreateEnvironment( | 6203 static i::Handle<ObjectType> CreateEnvironment( |
6200 i::Isolate* isolate, v8::ExtensionConfiguration* extensions, | 6204 i::Isolate* isolate, v8::ExtensionConfiguration* extensions, |
6201 v8::MaybeLocal<ObjectTemplate> maybe_global_template, | 6205 v8::MaybeLocal<ObjectTemplate> maybe_global_template, |
6202 v8::MaybeLocal<Value> maybe_global_proxy, size_t context_snapshot_index, | 6206 v8::MaybeLocal<Value> maybe_global_proxy, size_t context_snapshot_index, |
6203 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { | 6207 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { |
6204 i::Handle<ObjectType> result; | 6208 i::Handle<ObjectType> result; |
6205 | 6209 |
6206 // Enter V8 via an ENTER_V8 scope. | |
6207 { | 6210 { |
6208 ENTER_V8(isolate); | 6211 ENTER_V8_FOR_NEW_CONTEXT(isolate); |
6209 v8::Local<ObjectTemplate> proxy_template; | 6212 v8::Local<ObjectTemplate> proxy_template; |
6210 i::Handle<i::FunctionTemplateInfo> proxy_constructor; | 6213 i::Handle<i::FunctionTemplateInfo> proxy_constructor; |
6211 i::Handle<i::FunctionTemplateInfo> global_constructor; | 6214 i::Handle<i::FunctionTemplateInfo> global_constructor; |
| 6215 i::Handle<i::Object> named_interceptor( |
| 6216 isolate->factory()->undefined_value()); |
| 6217 i::Handle<i::Object> indexed_interceptor( |
| 6218 isolate->factory()->undefined_value()); |
6212 | 6219 |
6213 if (!maybe_global_template.IsEmpty()) { | 6220 if (!maybe_global_template.IsEmpty()) { |
6214 v8::Local<v8::ObjectTemplate> global_template = | 6221 v8::Local<v8::ObjectTemplate> global_template = |
6215 maybe_global_template.ToLocalChecked(); | 6222 maybe_global_template.ToLocalChecked(); |
6216 // Make sure that the global_template has a constructor. | 6223 // Make sure that the global_template has a constructor. |
6217 global_constructor = EnsureConstructor(isolate, *global_template); | 6224 global_constructor = EnsureConstructor(isolate, *global_template); |
6218 | 6225 |
6219 // Create a fresh template for the global proxy object. | 6226 // Create a fresh template for the global proxy object. |
6220 proxy_template = ObjectTemplate::New( | 6227 proxy_template = ObjectTemplate::New( |
6221 reinterpret_cast<v8::Isolate*>(isolate)); | 6228 reinterpret_cast<v8::Isolate*>(isolate)); |
(...skipping 12 matching lines...) Expand all Loading... |
6234 // information from the global template. | 6241 // information from the global template. |
6235 if (!global_constructor->access_check_info()->IsUndefined(isolate)) { | 6242 if (!global_constructor->access_check_info()->IsUndefined(isolate)) { |
6236 proxy_constructor->set_access_check_info( | 6243 proxy_constructor->set_access_check_info( |
6237 global_constructor->access_check_info()); | 6244 global_constructor->access_check_info()); |
6238 proxy_constructor->set_needs_access_check( | 6245 proxy_constructor->set_needs_access_check( |
6239 global_constructor->needs_access_check()); | 6246 global_constructor->needs_access_check()); |
6240 global_constructor->set_needs_access_check(false); | 6247 global_constructor->set_needs_access_check(false); |
6241 global_constructor->set_access_check_info( | 6248 global_constructor->set_access_check_info( |
6242 isolate->heap()->undefined_value()); | 6249 isolate->heap()->undefined_value()); |
6243 } | 6250 } |
| 6251 |
| 6252 // Same for other interceptors. If the global constructor has |
| 6253 // interceptors, we need to replace them temporarily with noop |
| 6254 // interceptors, so the map is correctly marked as having interceptors, |
| 6255 // but we don't invoke any. |
| 6256 if (!global_constructor->named_property_handler()->IsUndefined(isolate)) { |
| 6257 named_interceptor = |
| 6258 handle(global_constructor->named_property_handler(), isolate); |
| 6259 global_constructor->set_named_property_handler( |
| 6260 isolate->heap()->noop_interceptor_info()); |
| 6261 } |
| 6262 if (!global_constructor->indexed_property_handler()->IsUndefined( |
| 6263 isolate)) { |
| 6264 indexed_interceptor = |
| 6265 handle(global_constructor->indexed_property_handler(), isolate); |
| 6266 global_constructor->set_indexed_property_handler( |
| 6267 isolate->heap()->noop_interceptor_info()); |
| 6268 } |
6244 } | 6269 } |
6245 | 6270 |
6246 i::MaybeHandle<i::JSGlobalProxy> maybe_proxy; | 6271 i::MaybeHandle<i::JSGlobalProxy> maybe_proxy; |
6247 if (!maybe_global_proxy.IsEmpty()) { | 6272 if (!maybe_global_proxy.IsEmpty()) { |
6248 maybe_proxy = i::Handle<i::JSGlobalProxy>::cast( | 6273 maybe_proxy = i::Handle<i::JSGlobalProxy>::cast( |
6249 Utils::OpenHandle(*maybe_global_proxy.ToLocalChecked())); | 6274 Utils::OpenHandle(*maybe_global_proxy.ToLocalChecked())); |
6250 } | 6275 } |
6251 // Create the environment. | 6276 // Create the environment. |
6252 InvokeBootstrapper<ObjectType> invoke; | 6277 InvokeBootstrapper<ObjectType> invoke; |
6253 result = | 6278 result = |
6254 invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions, | 6279 invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions, |
6255 context_snapshot_index, internal_fields_deserializer); | 6280 context_snapshot_index, internal_fields_deserializer); |
6256 | 6281 |
6257 // Restore the access check info on the global template. | 6282 // Restore the access check info and interceptors on the global template. |
6258 if (!maybe_global_template.IsEmpty()) { | 6283 if (!maybe_global_template.IsEmpty()) { |
6259 DCHECK(!global_constructor.is_null()); | 6284 DCHECK(!global_constructor.is_null()); |
6260 DCHECK(!proxy_constructor.is_null()); | 6285 DCHECK(!proxy_constructor.is_null()); |
6261 global_constructor->set_access_check_info( | 6286 global_constructor->set_access_check_info( |
6262 proxy_constructor->access_check_info()); | 6287 proxy_constructor->access_check_info()); |
6263 global_constructor->set_needs_access_check( | 6288 global_constructor->set_needs_access_check( |
6264 proxy_constructor->needs_access_check()); | 6289 proxy_constructor->needs_access_check()); |
| 6290 global_constructor->set_named_property_handler(*named_interceptor); |
| 6291 global_constructor->set_indexed_property_handler(*indexed_interceptor); |
6265 } | 6292 } |
6266 } | 6293 } |
6267 // Leave V8. | 6294 // Leave V8. |
6268 | 6295 |
6269 return result; | 6296 return result; |
6270 } | 6297 } |
6271 | 6298 |
6272 Local<Context> NewContext( | 6299 Local<Context> NewContext( |
6273 v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions, | 6300 v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions, |
6274 v8::MaybeLocal<ObjectTemplate> global_template, | 6301 v8::MaybeLocal<ObjectTemplate> global_template, |
(...skipping 3721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9996 Address callback_address = | 10023 Address callback_address = |
9997 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10024 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9998 VMState<EXTERNAL> state(isolate); | 10025 VMState<EXTERNAL> state(isolate); |
9999 ExternalCallbackScope call_scope(isolate, callback_address); | 10026 ExternalCallbackScope call_scope(isolate, callback_address); |
10000 callback(info); | 10027 callback(info); |
10001 } | 10028 } |
10002 | 10029 |
10003 | 10030 |
10004 } // namespace internal | 10031 } // namespace internal |
10005 } // namespace v8 | 10032 } // namespace v8 |
OLD | NEW |