Chromium Code Reviews

Side by Side Diff: src/api.cc

Issue 2636903002: Assert that context creation doesn't throw (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « no previous file | src/assert-scope.h » ('j') | src/execution.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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...)
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...)
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);
Yang 2017/01/17 09:54:23 What about stack overflow, which trigger RangeErro
jochen (gone - plz use gerrit) 2017/01/17 10:24:01 we'd just swallow the exception and return an empt
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...)
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.
6253 if (!global_constructor->named_property_handler()->IsUndefined(isolate)) {
6254 named_interceptor =
6255 handle(global_constructor->named_property_handler(), isolate);
6256 auto obj = CreateInterceptorInfo(
6257 isolate, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
6258 nullptr, Local<Value>(), PropertyHandlerFlags::kNone);
Yang 2017/01/17 09:54:22 Do we want a canonical no-op interceptor info, cre
jochen (gone - plz use gerrit) 2017/01/17 10:24:01 done
6259 global_constructor->set_named_property_handler(*obj);
6260 }
6261 if (!global_constructor->indexed_property_handler()->IsUndefined(
6262 isolate)) {
6263 indexed_interceptor =
6264 handle(global_constructor->indexed_property_handler(), isolate);
6265 auto obj = CreateInterceptorInfo(
6266 isolate, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
6267 nullptr, Local<Value>(), PropertyHandlerFlags::kNone);
6268 global_constructor->set_indexed_property_handler(*obj);
6269 }
6244 } 6270 }
6245 6271
6246 i::MaybeHandle<i::JSGlobalProxy> maybe_proxy; 6272 i::MaybeHandle<i::JSGlobalProxy> maybe_proxy;
6247 if (!maybe_global_proxy.IsEmpty()) { 6273 if (!maybe_global_proxy.IsEmpty()) {
6248 maybe_proxy = i::Handle<i::JSGlobalProxy>::cast( 6274 maybe_proxy = i::Handle<i::JSGlobalProxy>::cast(
6249 Utils::OpenHandle(*maybe_global_proxy.ToLocalChecked())); 6275 Utils::OpenHandle(*maybe_global_proxy.ToLocalChecked()));
6250 } 6276 }
6251 // Create the environment. 6277 // Create the environment.
6252 InvokeBootstrapper<ObjectType> invoke; 6278 InvokeBootstrapper<ObjectType> invoke;
6253 result = 6279 result =
6254 invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions, 6280 invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions,
6255 context_snapshot_index, internal_fields_deserializer); 6281 context_snapshot_index, internal_fields_deserializer);
6256 6282
6257 // Restore the access check info on the global template. 6283 // Restore the access check info and interceptors on the global template.
6258 if (!maybe_global_template.IsEmpty()) { 6284 if (!maybe_global_template.IsEmpty()) {
6259 DCHECK(!global_constructor.is_null()); 6285 DCHECK(!global_constructor.is_null());
6260 DCHECK(!proxy_constructor.is_null()); 6286 DCHECK(!proxy_constructor.is_null());
6261 global_constructor->set_access_check_info( 6287 global_constructor->set_access_check_info(
6262 proxy_constructor->access_check_info()); 6288 proxy_constructor->access_check_info());
6263 global_constructor->set_needs_access_check( 6289 global_constructor->set_needs_access_check(
6264 proxy_constructor->needs_access_check()); 6290 proxy_constructor->needs_access_check());
6291 global_constructor->set_named_property_handler(*named_interceptor);
6292 global_constructor->set_indexed_property_handler(*indexed_interceptor);
6265 } 6293 }
6266 } 6294 }
6267 // Leave V8. 6295 // Leave V8.
6268 6296
6269 return result; 6297 return result;
6270 } 6298 }
6271 6299
6272 Local<Context> NewContext( 6300 Local<Context> NewContext(
6273 v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions, 6301 v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions,
6274 v8::MaybeLocal<ObjectTemplate> global_template, 6302 v8::MaybeLocal<ObjectTemplate> global_template,
(...skipping 3721 matching lines...)
9996 Address callback_address = 10024 Address callback_address =
9997 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10025 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9998 VMState<EXTERNAL> state(isolate); 10026 VMState<EXTERNAL> state(isolate);
9999 ExternalCallbackScope call_scope(isolate, callback_address); 10027 ExternalCallbackScope call_scope(isolate, callback_address);
10000 callback(info); 10028 callback(info);
10001 } 10029 }
10002 10030
10003 10031
10004 } // namespace internal 10032 } // namespace internal
10005 } // namespace v8 10033 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/assert-scope.h » ('j') | src/execution.h » ('J')

Powered by Google App Engine