Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: src/api.cc

Issue 2028983002: Introduce IsUndefined(Isolate*) and IsTheHole(Isolate*) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fixing wrongly wrapped lines Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 1068
1069 static Local<ObjectTemplate> ObjectTemplateNew( 1069 static Local<ObjectTemplate> ObjectTemplateNew(
1070 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor, 1070 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor,
1071 bool do_not_cache); 1071 bool do_not_cache);
1072 1072
1073 Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { 1073 Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() {
1074 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); 1074 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
1075 ENTER_V8(i_isolate); 1075 ENTER_V8(i_isolate);
1076 i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template(), 1076 i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template(),
1077 i_isolate); 1077 i_isolate);
1078 if (result->IsUndefined()) { 1078 if (result->IsUndefined(i_isolate)) {
1079 // Do not cache prototype objects. 1079 // Do not cache prototype objects.
1080 result = Utils::OpenHandle( 1080 result = Utils::OpenHandle(
1081 *ObjectTemplateNew(i_isolate, Local<FunctionTemplate>(), true)); 1081 *ObjectTemplateNew(i_isolate, Local<FunctionTemplate>(), true));
1082 Utils::OpenHandle(this)->set_prototype_template(*result); 1082 Utils::OpenHandle(this)->set_prototype_template(*result);
1083 } 1083 }
1084 return ToApiHandle<ObjectTemplate>(result); 1084 return ToApiHandle<ObjectTemplate>(result);
1085 } 1085 }
1086 1086
1087 1087
1088 static void EnsureNotInstantiated(i::Handle<i::FunctionTemplateInfo> info, 1088 static void EnsureNotInstantiated(i::Handle<i::FunctionTemplateInfo> info,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 1248
1249 Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { 1249 Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() {
1250 i::Handle<i::FunctionTemplateInfo> handle = Utils::OpenHandle(this, true); 1250 i::Handle<i::FunctionTemplateInfo> handle = Utils::OpenHandle(this, true);
1251 if (!Utils::ApiCheck(!handle.is_null(), 1251 if (!Utils::ApiCheck(!handle.is_null(),
1252 "v8::FunctionTemplate::InstanceTemplate()", 1252 "v8::FunctionTemplate::InstanceTemplate()",
1253 "Reading from empty handle")) { 1253 "Reading from empty handle")) {
1254 return Local<ObjectTemplate>(); 1254 return Local<ObjectTemplate>();
1255 } 1255 }
1256 i::Isolate* isolate = handle->GetIsolate(); 1256 i::Isolate* isolate = handle->GetIsolate();
1257 ENTER_V8(isolate); 1257 ENTER_V8(isolate);
1258 if (handle->instance_template()->IsUndefined()) { 1258 if (handle->instance_template()->IsUndefined(isolate)) {
1259 Local<ObjectTemplate> templ = 1259 Local<ObjectTemplate> templ =
1260 ObjectTemplate::New(isolate, ToApiHandle<FunctionTemplate>(handle)); 1260 ObjectTemplate::New(isolate, ToApiHandle<FunctionTemplate>(handle));
1261 handle->set_instance_template(*Utils::OpenHandle(*templ)); 1261 handle->set_instance_template(*Utils::OpenHandle(*templ));
1262 } 1262 }
1263 i::Handle<i::ObjectTemplateInfo> result( 1263 i::Handle<i::ObjectTemplateInfo> result(
1264 i::ObjectTemplateInfo::cast(handle->instance_template())); 1264 i::ObjectTemplateInfo::cast(handle->instance_template()));
1265 return Utils::ToLocal(result); 1265 return Utils::ToLocal(result);
1266 } 1266 }
1267 1267
1268 1268
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) { 1362 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) {
1363 return ObjectTemplateNew(isolate, constructor, false); 1363 return ObjectTemplateNew(isolate, constructor, false);
1364 } 1364 }
1365 1365
1366 // Ensure that the object template has a constructor. If no 1366 // Ensure that the object template has a constructor. If no
1367 // constructor is available we create one. 1367 // constructor is available we create one.
1368 static i::Handle<i::FunctionTemplateInfo> EnsureConstructor( 1368 static i::Handle<i::FunctionTemplateInfo> EnsureConstructor(
1369 i::Isolate* isolate, 1369 i::Isolate* isolate,
1370 ObjectTemplate* object_template) { 1370 ObjectTemplate* object_template) {
1371 i::Object* obj = Utils::OpenHandle(object_template)->constructor(); 1371 i::Object* obj = Utils::OpenHandle(object_template)->constructor();
1372 if (!obj ->IsUndefined()) { 1372 if (!obj->IsUndefined(isolate)) {
1373 i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj); 1373 i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj);
1374 return i::Handle<i::FunctionTemplateInfo>(info, isolate); 1374 return i::Handle<i::FunctionTemplateInfo>(info, isolate);
1375 } 1375 }
1376 Local<FunctionTemplate> templ = 1376 Local<FunctionTemplate> templ =
1377 FunctionTemplate::New(reinterpret_cast<Isolate*>(isolate)); 1377 FunctionTemplate::New(reinterpret_cast<Isolate*>(isolate));
1378 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); 1378 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ);
1379 constructor->set_instance_template(*Utils::OpenHandle(object_template)); 1379 constructor->set_instance_template(*Utils::OpenHandle(object_template));
1380 Utils::OpenHandle(object_template)->set_constructor(*constructor); 1380 Utils::OpenHandle(object_template)->set_constructor(*constructor);
1381 return constructor; 1381 return constructor;
1382 } 1382 }
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after
2311 2311
2312 v8::Local<Value> v8::TryCatch::StackTrace() const { 2312 v8::Local<Value> v8::TryCatch::StackTrace() const {
2313 auto context = reinterpret_cast<v8::Isolate*>(isolate_)->GetCurrentContext(); 2313 auto context = reinterpret_cast<v8::Isolate*>(isolate_)->GetCurrentContext();
2314 RETURN_TO_LOCAL_UNCHECKED(StackTrace(context), Value); 2314 RETURN_TO_LOCAL_UNCHECKED(StackTrace(context), Value);
2315 } 2315 }
2316 2316
2317 2317
2318 v8::Local<v8::Message> v8::TryCatch::Message() const { 2318 v8::Local<v8::Message> v8::TryCatch::Message() const {
2319 i::Object* message = reinterpret_cast<i::Object*>(message_obj_); 2319 i::Object* message = reinterpret_cast<i::Object*>(message_obj_);
2320 DCHECK(message->IsJSMessageObject() || message->IsTheHole()); 2320 DCHECK(message->IsJSMessageObject() || message->IsTheHole());
2321 if (HasCaught() && !message->IsTheHole()) { 2321 if (HasCaught() && !message->IsTheHole(isolate_)) {
2322 return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_)); 2322 return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_));
2323 } else { 2323 } else {
2324 return v8::Local<v8::Message>(); 2324 return v8::Local<v8::Message>();
2325 } 2325 }
2326 } 2326 }
2327 2327
2328 2328
2329 void v8::TryCatch::Reset() { 2329 void v8::TryCatch::Reset() {
2330 if (!rethrow_ && HasCaught() && isolate_->has_scheduled_exception()) { 2330 if (!rethrow_ && HasCaught() && isolate_->has_scheduled_exception()) {
2331 // If an exception was caught but is still scheduled because no API call 2331 // If an exception was caught but is still scheduled because no API call
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
2680 DCHECK(false); 2680 DCHECK(false);
2681 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); 2681 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
2682 } 2682 }
2683 i::Handle<i::ObjectHashTable> table( 2683 i::Handle<i::ObjectHashTable> table(
2684 i::ObjectHashTable::cast(weak_collection->table())); 2684 i::ObjectHashTable::cast(weak_collection->table()));
2685 if (!table->IsKey(*key)) { 2685 if (!table->IsKey(*key)) {
2686 DCHECK(false); 2686 DCHECK(false);
2687 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); 2687 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
2688 } 2688 }
2689 i::Handle<i::Object> lookup(table->Lookup(key), isolate); 2689 i::Handle<i::Object> lookup(table->Lookup(key), isolate);
2690 if (lookup->IsTheHole()) 2690 if (lookup->IsTheHole(isolate))
2691 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); 2691 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
2692 return Utils::ToLocal(lookup); 2692 return Utils::ToLocal(lookup);
2693 } 2693 }
2694 2694
2695 2695
2696 bool NativeWeakMap::Has(Local<Value> v8_key) { 2696 bool NativeWeakMap::Has(Local<Value> v8_key) {
2697 i::Handle<i::JSWeakMap> weak_collection = Utils::OpenHandle(this); 2697 i::Handle<i::JSWeakMap> weak_collection = Utils::OpenHandle(this);
2698 i::Isolate* isolate = weak_collection->GetIsolate(); 2698 i::Isolate* isolate = weak_collection->GetIsolate();
2699 ENTER_V8(isolate); 2699 ENTER_V8(isolate);
2700 i::HandleScope scope(isolate); 2700 i::HandleScope scope(isolate);
2701 i::Handle<i::Object> key = Utils::OpenHandle(*v8_key); 2701 i::Handle<i::Object> key = Utils::OpenHandle(*v8_key);
2702 if (!key->IsJSReceiver() && !key->IsSymbol()) { 2702 if (!key->IsJSReceiver() && !key->IsSymbol()) {
2703 DCHECK(false); 2703 DCHECK(false);
2704 return false; 2704 return false;
2705 } 2705 }
2706 i::Handle<i::ObjectHashTable> table( 2706 i::Handle<i::ObjectHashTable> table(
2707 i::ObjectHashTable::cast(weak_collection->table())); 2707 i::ObjectHashTable::cast(weak_collection->table()));
2708 if (!table->IsKey(*key)) { 2708 if (!table->IsKey(*key)) {
2709 DCHECK(false); 2709 DCHECK(false);
2710 return false; 2710 return false;
2711 } 2711 }
2712 i::Handle<i::Object> lookup(table->Lookup(key), isolate); 2712 i::Handle<i::Object> lookup(table->Lookup(key), isolate);
2713 return !lookup->IsTheHole(); 2713 return !lookup->IsTheHole(isolate);
2714 } 2714 }
2715 2715
2716 2716
2717 bool NativeWeakMap::Delete(Local<Value> v8_key) { 2717 bool NativeWeakMap::Delete(Local<Value> v8_key) {
2718 i::Handle<i::JSWeakMap> weak_collection = Utils::OpenHandle(this); 2718 i::Handle<i::JSWeakMap> weak_collection = Utils::OpenHandle(this);
2719 i::Isolate* isolate = weak_collection->GetIsolate(); 2719 i::Isolate* isolate = weak_collection->GetIsolate();
2720 ENTER_V8(isolate); 2720 ENTER_V8(isolate);
2721 i::HandleScope scope(isolate); 2721 i::HandleScope scope(isolate);
2722 i::Handle<i::Object> key = Utils::OpenHandle(*v8_key); 2722 i::Handle<i::Object> key = Utils::OpenHandle(*v8_key);
2723 if (!key->IsJSReceiver() && !key->IsSymbol()) { 2723 if (!key->IsJSReceiver() && !key->IsSymbol()) {
(...skipping 2837 matching lines...) Expand 10 before | Expand all | Expand 10 after
5561 proxy_constructor = EnsureConstructor(isolate, *proxy_template); 5561 proxy_constructor = EnsureConstructor(isolate, *proxy_template);
5562 5562
5563 // Set the global template to be the prototype template of 5563 // Set the global template to be the prototype template of
5564 // global proxy template. 5564 // global proxy template.
5565 proxy_constructor->set_prototype_template( 5565 proxy_constructor->set_prototype_template(
5566 *Utils::OpenHandle(*global_template)); 5566 *Utils::OpenHandle(*global_template));
5567 5567
5568 // Migrate security handlers from global_template to 5568 // Migrate security handlers from global_template to
5569 // proxy_template. Temporarily removing access check 5569 // proxy_template. Temporarily removing access check
5570 // information from the global template. 5570 // information from the global template.
5571 if (!global_constructor->access_check_info()->IsUndefined()) { 5571 if (!global_constructor->access_check_info()->IsUndefined(isolate)) {
5572 proxy_constructor->set_access_check_info( 5572 proxy_constructor->set_access_check_info(
5573 global_constructor->access_check_info()); 5573 global_constructor->access_check_info());
5574 proxy_constructor->set_needs_access_check( 5574 proxy_constructor->set_needs_access_check(
5575 global_constructor->needs_access_check()); 5575 global_constructor->needs_access_check());
5576 global_constructor->set_needs_access_check(false); 5576 global_constructor->set_needs_access_check(false);
5577 global_constructor->set_access_check_info( 5577 global_constructor->set_access_check_info(
5578 isolate->heap()->undefined_value()); 5578 isolate->heap()->undefined_value());
5579 } 5579 }
5580 } 5580 }
5581 5581
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after
6935 i::Handle<i::String> name, 6935 i::Handle<i::String> name,
6936 i::Handle<i::String> part, 6936 i::Handle<i::String> part,
6937 bool private_symbol) { 6937 bool private_symbol) {
6938 i::Handle<i::JSObject> registry = isolate->GetSymbolRegistry(); 6938 i::Handle<i::JSObject> registry = isolate->GetSymbolRegistry();
6939 i::Handle<i::JSObject> symbols = 6939 i::Handle<i::JSObject> symbols =
6940 i::Handle<i::JSObject>::cast( 6940 i::Handle<i::JSObject>::cast(
6941 i::Object::GetPropertyOrElement(registry, part).ToHandleChecked()); 6941 i::Object::GetPropertyOrElement(registry, part).ToHandleChecked());
6942 i::Handle<i::Object> symbol = 6942 i::Handle<i::Object> symbol =
6943 i::Object::GetPropertyOrElement(symbols, name).ToHandleChecked(); 6943 i::Object::GetPropertyOrElement(symbols, name).ToHandleChecked();
6944 if (!symbol->IsSymbol()) { 6944 if (!symbol->IsSymbol()) {
6945 DCHECK(symbol->IsUndefined()); 6945 DCHECK(symbol->IsUndefined(isolate));
6946 if (private_symbol) 6946 if (private_symbol)
6947 symbol = isolate->factory()->NewPrivateSymbol(); 6947 symbol = isolate->factory()->NewPrivateSymbol();
6948 else 6948 else
6949 symbol = isolate->factory()->NewSymbol(); 6949 symbol = isolate->factory()->NewSymbol();
6950 i::Handle<i::Symbol>::cast(symbol)->set_name(*name); 6950 i::Handle<i::Symbol>::cast(symbol)->set_name(*name);
6951 i::Object::SetPropertyOrElement(symbols, name, symbol, i::STRICT).Assert(); 6951 i::Object::SetPropertyOrElement(symbols, name, symbol, i::STRICT).Assert();
6952 } 6952 }
6953 return i::Handle<i::Symbol>::cast(symbol); 6953 return i::Handle<i::Symbol>::cast(symbol);
6954 } 6954 }
6955 6955
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
7755 return true; 7755 return true;
7756 } 7756 }
7757 7757
7758 7758
7759 void Isolate::RemoveMessageListeners(MessageCallback that) { 7759 void Isolate::RemoveMessageListeners(MessageCallback that) {
7760 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); 7760 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
7761 ENTER_V8(isolate); 7761 ENTER_V8(isolate);
7762 i::HandleScope scope(isolate); 7762 i::HandleScope scope(isolate);
7763 NeanderArray listeners(isolate->factory()->message_listeners()); 7763 NeanderArray listeners(isolate->factory()->message_listeners());
7764 for (int i = 0; i < listeners.length(); i++) { 7764 for (int i = 0; i < listeners.length(); i++) {
7765 if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones 7765 if (listeners.get(i)->IsUndefined(isolate)) continue; // skip deleted ones
7766 7766
7767 NeanderObject listener(i::JSObject::cast(listeners.get(i))); 7767 NeanderObject listener(i::JSObject::cast(listeners.get(i)));
7768 i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listener.get(0))); 7768 i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listener.get(0)));
7769 if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) { 7769 if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) {
7770 listeners.set(i, isolate->heap()->undefined_value()); 7770 listeners.set(i, isolate->heap()->undefined_value());
7771 } 7771 }
7772 } 7772 }
7773 } 7773 }
7774 7774
7775 7775
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after
8817 Address callback_address = 8817 Address callback_address =
8818 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8818 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8819 VMState<EXTERNAL> state(isolate); 8819 VMState<EXTERNAL> state(isolate);
8820 ExternalCallbackScope call_scope(isolate, callback_address); 8820 ExternalCallbackScope call_scope(isolate, callback_address);
8821 callback(info); 8821 callback(info);
8822 } 8822 }
8823 8823
8824 8824
8825 } // namespace internal 8825 } // namespace internal
8826 } // namespace v8 8826 } // namespace v8
OLDNEW
« no previous file with comments | « src/accessors.cc ('k') | src/api-natives.cc » ('j') | src/debug/debug.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698