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 3004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3015 if (num->IsSmi()) { | 3015 if (num->IsSmi()) { |
3016 return i::Smi::cast(*num)->value(); | 3016 return i::Smi::cast(*num)->value(); |
3017 } else { | 3017 } else { |
3018 return static_cast<int32_t>(num->Number()); | 3018 return static_cast<int32_t>(num->Number()); |
3019 } | 3019 } |
3020 } | 3020 } |
3021 } | 3021 } |
3022 | 3022 |
3023 | 3023 |
3024 bool Value::Equals(Handle<Value> that) const { | 3024 bool Value::Equals(Handle<Value> that) const { |
3025 i::Isolate* isolate = i::Isolate::Current(); | |
3026 i::Handle<i::Object> obj = Utils::OpenHandle(this, true); | 3025 i::Handle<i::Object> obj = Utils::OpenHandle(this, true); |
3026 i::Handle<i::Object> other = Utils::OpenHandle(*that); | |
3027 if (obj->IsSmi() && other->IsSmi()) { | |
3028 return obj->Number() == other->Number(); | |
3029 } | |
3030 i::Isolate* isolate = NULL; | |
3031 if (!obj->IsSmi()) { | |
3032 isolate = i::HeapObject::cast(*obj)->GetIsolate(); | |
3033 } else { | |
3034 isolate = i::HeapObject::cast(*other)->GetIsolate(); | |
3035 } | |
Sven Panne
2014/11/06 07:29:35
Shorter and more readable version:
i::Object* ho
| |
3027 if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(), | 3036 if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(), |
3028 "v8::Value::Equals()", | 3037 "v8::Value::Equals()", |
3029 "Reading from empty handle")) { | 3038 "Reading from empty handle")) { |
3030 return false; | 3039 return false; |
3031 } | 3040 } |
3032 LOG_API(isolate, "Equals"); | 3041 LOG_API(isolate, "Equals"); |
3033 ENTER_V8(isolate); | 3042 ENTER_V8(isolate); |
3034 i::Handle<i::Object> other = Utils::OpenHandle(*that); | |
3035 // If both obj and other are JSObjects, we'd better compare by identity | 3043 // If both obj and other are JSObjects, we'd better compare by identity |
3036 // immediately when going into JS builtin. The reason is Invoke | 3044 // immediately when going into JS builtin. The reason is Invoke |
3037 // would overwrite global object receiver with global proxy. | 3045 // would overwrite global object receiver with global proxy. |
3038 if (obj->IsJSObject() && other->IsJSObject()) { | 3046 if (obj->IsJSObject() && other->IsJSObject()) { |
3039 return *obj == *other; | 3047 return *obj == *other; |
3040 } | 3048 } |
3041 i::Handle<i::Object> args[] = { other }; | 3049 i::Handle<i::Object> args[] = { other }; |
3042 EXCEPTION_PREAMBLE(isolate); | 3050 EXCEPTION_PREAMBLE(isolate); |
3043 i::Handle<i::Object> result; | 3051 i::Handle<i::Object> result; |
3044 has_pending_exception = | 3052 has_pending_exception = |
3045 !CallV8HeapFunction(isolate, "EQUALS", obj, arraysize(args), args) | 3053 !CallV8HeapFunction(isolate, "EQUALS", obj, arraysize(args), args) |
3046 .ToHandle(&result); | 3054 .ToHandle(&result); |
3047 EXCEPTION_BAILOUT_CHECK(isolate, false); | 3055 EXCEPTION_BAILOUT_CHECK(isolate, false); |
3048 return *result == i::Smi::FromInt(i::EQUAL); | 3056 return *result == i::Smi::FromInt(i::EQUAL); |
3049 } | 3057 } |
3050 | 3058 |
3051 | 3059 |
3052 bool Value::StrictEquals(Handle<Value> that) const { | 3060 bool Value::StrictEquals(Handle<Value> that) const { |
3053 i::Isolate* isolate = i::Isolate::Current(); | |
3054 i::Handle<i::Object> obj = Utils::OpenHandle(this, true); | 3061 i::Handle<i::Object> obj = Utils::OpenHandle(this, true); |
3062 i::Handle<i::Object> other = Utils::OpenHandle(*that); | |
3063 if (obj->IsSmi()) { | |
3064 return other->IsNumber() && obj->Number() == other->Number(); | |
3065 } | |
3066 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); | |
3055 if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(), | 3067 if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(), |
3056 "v8::Value::StrictEquals()", | 3068 "v8::Value::StrictEquals()", |
3057 "Reading from empty handle")) { | 3069 "Reading from empty handle")) { |
3058 return false; | 3070 return false; |
3059 } | 3071 } |
3060 LOG_API(isolate, "StrictEquals"); | 3072 LOG_API(isolate, "StrictEquals"); |
3061 i::Handle<i::Object> other = Utils::OpenHandle(*that); | |
3062 // Must check HeapNumber first, since NaN !== NaN. | 3073 // Must check HeapNumber first, since NaN !== NaN. |
3063 if (obj->IsHeapNumber()) { | 3074 if (obj->IsHeapNumber()) { |
3064 if (!other->IsNumber()) return false; | 3075 if (!other->IsNumber()) return false; |
3065 double x = obj->Number(); | 3076 double x = obj->Number(); |
3066 double y = other->Number(); | 3077 double y = other->Number(); |
3067 // Must check explicitly for NaN:s on Windows, but -0 works fine. | 3078 // Must check explicitly for NaN:s on Windows, but -0 works fine. |
3068 return x == y && !std::isnan(x) && !std::isnan(y); | 3079 return x == y && !std::isnan(x) && !std::isnan(y); |
3069 } else if (*obj == *other) { // Also covers Booleans. | 3080 } else if (*obj == *other) { // Also covers Booleans. |
3070 return true; | 3081 return true; |
3071 } else if (obj->IsSmi()) { | 3082 } else if (obj->IsSmi()) { |
(...skipping 4699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7771 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7782 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7772 Address callback_address = | 7783 Address callback_address = |
7773 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7784 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7774 VMState<EXTERNAL> state(isolate); | 7785 VMState<EXTERNAL> state(isolate); |
7775 ExternalCallbackScope call_scope(isolate, callback_address); | 7786 ExternalCallbackScope call_scope(isolate, callback_address); |
7776 callback(info); | 7787 callback(info); |
7777 } | 7788 } |
7778 | 7789 |
7779 | 7790 |
7780 } } // namespace v8::internal | 7791 } } // namespace v8::internal |
OLD | NEW |