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 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate(); | 1185 i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate(); |
1186 if (descriptor.IsEmpty()) return i::Handle<i::DeclaredAccessorInfo>(); | 1186 if (descriptor.IsEmpty()) return i::Handle<i::DeclaredAccessorInfo>(); |
1187 i::Handle<i::DeclaredAccessorInfo> obj = | 1187 i::Handle<i::DeclaredAccessorInfo> obj = |
1188 isolate->factory()->NewDeclaredAccessorInfo(); | 1188 isolate->factory()->NewDeclaredAccessorInfo(); |
1189 obj->set_descriptor(*Utils::OpenHandle(*descriptor)); | 1189 obj->set_descriptor(*Utils::OpenHandle(*descriptor)); |
1190 return SetAccessorInfoProperties(obj, name, settings, attributes, signature); | 1190 return SetAccessorInfoProperties(obj, name, settings, attributes, signature); |
1191 } | 1191 } |
1192 | 1192 |
1193 | 1193 |
1194 Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { | 1194 Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { |
1195 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 1195 i::Handle<i::FunctionTemplateInfo> handle = Utils::OpenHandle(this, true); |
1196 if (!Utils::ApiCheck(this != NULL, | 1196 if (!Utils::ApiCheck(!handle.is_null(), |
1197 "v8::FunctionTemplate::InstanceTemplate()", | 1197 "v8::FunctionTemplate::InstanceTemplate()", |
1198 "Reading from empty handle")) { | 1198 "Reading from empty handle")) { |
1199 return Local<ObjectTemplate>(); | 1199 return Local<ObjectTemplate>(); |
1200 } | 1200 } |
| 1201 i::Isolate* isolate = handle->GetIsolate(); |
1201 ENTER_V8(isolate); | 1202 ENTER_V8(isolate); |
1202 i::Handle<i::FunctionTemplateInfo> handle = Utils::OpenHandle(this); | |
1203 if (handle->instance_template()->IsUndefined()) { | 1203 if (handle->instance_template()->IsUndefined()) { |
1204 Local<ObjectTemplate> templ = | 1204 Local<ObjectTemplate> templ = |
1205 ObjectTemplate::New(isolate, ToApiHandle<FunctionTemplate>(handle)); | 1205 ObjectTemplate::New(isolate, ToApiHandle<FunctionTemplate>(handle)); |
1206 handle->set_instance_template(*Utils::OpenHandle(*templ)); | 1206 handle->set_instance_template(*Utils::OpenHandle(*templ)); |
1207 } | 1207 } |
1208 i::Handle<i::ObjectTemplateInfo> result( | 1208 i::Handle<i::ObjectTemplateInfo> result( |
1209 i::ObjectTemplateInfo::cast(handle->instance_template())); | 1209 i::ObjectTemplateInfo::cast(handle->instance_template())); |
1210 return Utils::ToLocal(result); | 1210 return Utils::ToLocal(result); |
1211 } | 1211 } |
1212 | 1212 |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1609 if (obj->script()->IsScript()) { | 1609 if (obj->script()->IsScript()) { |
1610 i::Object* name = i::Script::cast(obj->script())->name(); | 1610 i::Object* name = i::Script::cast(obj->script())->name(); |
1611 return Utils::ToLocal(i::Handle<i::Object>(name, isolate)); | 1611 return Utils::ToLocal(i::Handle<i::Object>(name, isolate)); |
1612 } else { | 1612 } else { |
1613 return Handle<String>(); | 1613 return Handle<String>(); |
1614 } | 1614 } |
1615 } | 1615 } |
1616 | 1616 |
1617 | 1617 |
1618 Local<Value> Script::Run() { | 1618 Local<Value> Script::Run() { |
| 1619 i::Handle<i::HeapObject> obj = |
| 1620 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this, true)); |
1619 // If execution is terminating, Compile(..)->Run() requires this | 1621 // If execution is terminating, Compile(..)->Run() requires this |
1620 // check. | 1622 // check. |
1621 if (this == NULL) return Local<Value>(); | 1623 if (obj.is_null()) return Local<Value>(); |
1622 i::Handle<i::HeapObject> obj = | |
1623 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); | |
1624 i::Isolate* isolate = obj->GetIsolate(); | 1624 i::Isolate* isolate = obj->GetIsolate(); |
1625 ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>()); | 1625 ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>()); |
1626 LOG_API(isolate, "Script::Run"); | 1626 LOG_API(isolate, "Script::Run"); |
1627 ENTER_V8(isolate); | 1627 ENTER_V8(isolate); |
1628 i::Logger::TimerEventScope timer_scope( | 1628 i::Logger::TimerEventScope timer_scope( |
1629 isolate, i::Logger::TimerEventScope::v8_execute); | 1629 isolate, i::Logger::TimerEventScope::v8_execute); |
1630 i::HandleScope scope(isolate); | 1630 i::HandleScope scope(isolate); |
1631 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(obj); | 1631 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(obj); |
1632 EXCEPTION_PREAMBLE(isolate); | 1632 EXCEPTION_PREAMBLE(isolate); |
1633 i::Handle<i::Object> receiver( | 1633 i::Handle<i::Object> receiver( |
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2905 return i::Smi::cast(*num)->value(); | 2905 return i::Smi::cast(*num)->value(); |
2906 } else { | 2906 } else { |
2907 return static_cast<int32_t>(num->Number()); | 2907 return static_cast<int32_t>(num->Number()); |
2908 } | 2908 } |
2909 } | 2909 } |
2910 } | 2910 } |
2911 | 2911 |
2912 | 2912 |
2913 bool Value::Equals(Handle<Value> that) const { | 2913 bool Value::Equals(Handle<Value> that) const { |
2914 i::Isolate* isolate = i::Isolate::Current(); | 2914 i::Isolate* isolate = i::Isolate::Current(); |
2915 if (!Utils::ApiCheck(this != NULL && !that.IsEmpty(), | 2915 i::Handle<i::Object> obj = Utils::OpenHandle(this, true); |
| 2916 if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(), |
2916 "v8::Value::Equals()", | 2917 "v8::Value::Equals()", |
2917 "Reading from empty handle")) { | 2918 "Reading from empty handle")) { |
2918 return false; | 2919 return false; |
2919 } | 2920 } |
2920 LOG_API(isolate, "Equals"); | 2921 LOG_API(isolate, "Equals"); |
2921 ENTER_V8(isolate); | 2922 ENTER_V8(isolate); |
2922 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
2923 i::Handle<i::Object> other = Utils::OpenHandle(*that); | 2923 i::Handle<i::Object> other = Utils::OpenHandle(*that); |
2924 // If both obj and other are JSObjects, we'd better compare by identity | 2924 // If both obj and other are JSObjects, we'd better compare by identity |
2925 // immediately when going into JS builtin. The reason is Invoke | 2925 // immediately when going into JS builtin. The reason is Invoke |
2926 // would overwrite global object receiver with global proxy. | 2926 // would overwrite global object receiver with global proxy. |
2927 if (obj->IsJSObject() && other->IsJSObject()) { | 2927 if (obj->IsJSObject() && other->IsJSObject()) { |
2928 return *obj == *other; | 2928 return *obj == *other; |
2929 } | 2929 } |
2930 i::Handle<i::Object> args[] = { other }; | 2930 i::Handle<i::Object> args[] = { other }; |
2931 EXCEPTION_PREAMBLE(isolate); | 2931 EXCEPTION_PREAMBLE(isolate); |
2932 i::Handle<i::Object> result; | 2932 i::Handle<i::Object> result; |
2933 has_pending_exception = !CallV8HeapFunction( | 2933 has_pending_exception = !CallV8HeapFunction( |
2934 "EQUALS", obj, ARRAY_SIZE(args), args).ToHandle(&result); | 2934 "EQUALS", obj, ARRAY_SIZE(args), args).ToHandle(&result); |
2935 EXCEPTION_BAILOUT_CHECK(isolate, false); | 2935 EXCEPTION_BAILOUT_CHECK(isolate, false); |
2936 return *result == i::Smi::FromInt(i::EQUAL); | 2936 return *result == i::Smi::FromInt(i::EQUAL); |
2937 } | 2937 } |
2938 | 2938 |
2939 | 2939 |
2940 bool Value::StrictEquals(Handle<Value> that) const { | 2940 bool Value::StrictEquals(Handle<Value> that) const { |
2941 i::Isolate* isolate = i::Isolate::Current(); | 2941 i::Isolate* isolate = i::Isolate::Current(); |
2942 if (!Utils::ApiCheck(this != NULL && !that.IsEmpty(), | 2942 i::Handle<i::Object> obj = Utils::OpenHandle(this, true); |
| 2943 if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(), |
2943 "v8::Value::StrictEquals()", | 2944 "v8::Value::StrictEquals()", |
2944 "Reading from empty handle")) { | 2945 "Reading from empty handle")) { |
2945 return false; | 2946 return false; |
2946 } | 2947 } |
2947 LOG_API(isolate, "StrictEquals"); | 2948 LOG_API(isolate, "StrictEquals"); |
2948 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
2949 i::Handle<i::Object> other = Utils::OpenHandle(*that); | 2949 i::Handle<i::Object> other = Utils::OpenHandle(*that); |
2950 // Must check HeapNumber first, since NaN !== NaN. | 2950 // Must check HeapNumber first, since NaN !== NaN. |
2951 if (obj->IsHeapNumber()) { | 2951 if (obj->IsHeapNumber()) { |
2952 if (!other->IsNumber()) return false; | 2952 if (!other->IsNumber()) return false; |
2953 double x = obj->Number(); | 2953 double x = obj->Number(); |
2954 double y = other->Number(); | 2954 double y = other->Number(); |
2955 // Must check explicitly for NaN:s on Windows, but -0 works fine. | 2955 // Must check explicitly for NaN:s on Windows, but -0 works fine. |
2956 return x == y && !std::isnan(x) && !std::isnan(y); | 2956 return x == y && !std::isnan(x) && !std::isnan(y); |
2957 } else if (*obj == *other) { // Also covers Booleans. | 2957 } else if (*obj == *other) { // Also covers Booleans. |
2958 return true; | 2958 return true; |
2959 } else if (obj->IsSmi()) { | 2959 } else if (obj->IsSmi()) { |
2960 return other->IsNumber() && obj->Number() == other->Number(); | 2960 return other->IsNumber() && obj->Number() == other->Number(); |
2961 } else if (obj->IsString()) { | 2961 } else if (obj->IsString()) { |
2962 return other->IsString() && | 2962 return other->IsString() && |
2963 i::String::Equals(i::Handle<i::String>::cast(obj), | 2963 i::String::Equals(i::Handle<i::String>::cast(obj), |
2964 i::Handle<i::String>::cast(other)); | 2964 i::Handle<i::String>::cast(other)); |
2965 } else if (obj->IsUndefined() || obj->IsUndetectableObject()) { | 2965 } else if (obj->IsUndefined() || obj->IsUndetectableObject()) { |
2966 return other->IsUndefined() || other->IsUndetectableObject(); | 2966 return other->IsUndefined() || other->IsUndetectableObject(); |
2967 } else { | 2967 } else { |
2968 return false; | 2968 return false; |
2969 } | 2969 } |
2970 } | 2970 } |
2971 | 2971 |
2972 | 2972 |
2973 bool Value::SameValue(Handle<Value> that) const { | 2973 bool Value::SameValue(Handle<Value> that) const { |
2974 if (!Utils::ApiCheck(this != NULL && !that.IsEmpty(), | 2974 i::Handle<i::Object> obj = Utils::OpenHandle(this, true); |
| 2975 if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(), |
2975 "v8::Value::SameValue()", | 2976 "v8::Value::SameValue()", |
2976 "Reading from empty handle")) { | 2977 "Reading from empty handle")) { |
2977 return false; | 2978 return false; |
2978 } | 2979 } |
2979 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
2980 i::Handle<i::Object> other = Utils::OpenHandle(*that); | 2980 i::Handle<i::Object> other = Utils::OpenHandle(*that); |
2981 return obj->SameValue(*other); | 2981 return obj->SameValue(*other); |
2982 } | 2982 } |
2983 | 2983 |
2984 | 2984 |
2985 uint32_t Value::Uint32Value() const { | 2985 uint32_t Value::Uint32Value() const { |
2986 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 2986 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
2987 if (obj->IsSmi()) { | 2987 if (obj->IsSmi()) { |
2988 return i::Smi::cast(*obj)->value(); | 2988 return i::Smi::cast(*obj)->value(); |
2989 } else { | 2989 } else { |
(...skipping 4589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7579 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7579 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7580 Address callback_address = | 7580 Address callback_address = |
7581 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7581 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7582 VMState<EXTERNAL> state(isolate); | 7582 VMState<EXTERNAL> state(isolate); |
7583 ExternalCallbackScope call_scope(isolate, callback_address); | 7583 ExternalCallbackScope call_scope(isolate, callback_address); |
7584 callback(info); | 7584 callback(info); |
7585 } | 7585 } |
7586 | 7586 |
7587 | 7587 |
7588 } } // namespace v8::internal | 7588 } } // namespace v8::internal |
OLD | NEW |