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

Side by Side Diff: src/api.cc

Issue 1306303003: [es6] Implement spec compliant ToPrimitive in the runtime. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address Michis comments. Created 5 years, 3 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 2836 matching lines...) Expand 10 before | Expand all | Expand 10 after
2847 return Utils::OpenHandle(this)->IsJSSetIterator(); 2847 return Utils::OpenHandle(this)->IsJSSetIterator();
2848 } 2848 }
2849 2849
2850 2850
2851 MaybeLocal<String> Value::ToString(Local<Context> context) const { 2851 MaybeLocal<String> Value::ToString(Local<Context> context) const {
2852 auto obj = Utils::OpenHandle(this); 2852 auto obj = Utils::OpenHandle(this);
2853 if (obj->IsString()) return ToApiHandle<String>(obj); 2853 if (obj->IsString()) return ToApiHandle<String>(obj);
2854 PREPARE_FOR_EXECUTION(context, "ToString", String); 2854 PREPARE_FOR_EXECUTION(context, "ToString", String);
2855 Local<String> result; 2855 Local<String> result;
2856 has_pending_exception = 2856 has_pending_exception =
2857 !ToLocal<String>(i::Execution::ToString(isolate, obj), &result); 2857 !ToLocal<String>(i::Object::ToString(isolate, obj), &result);
2858 RETURN_ON_FAILED_EXECUTION(String); 2858 RETURN_ON_FAILED_EXECUTION(String);
2859 RETURN_ESCAPED(result); 2859 RETURN_ESCAPED(result);
2860 } 2860 }
2861 2861
2862 2862
2863 Local<String> Value::ToString(Isolate* isolate) const { 2863 Local<String> Value::ToString(Isolate* isolate) const {
2864 RETURN_TO_LOCAL_UNCHECKED(ToString(isolate->GetCurrentContext()), String); 2864 RETURN_TO_LOCAL_UNCHECKED(ToString(isolate->GetCurrentContext()), String);
2865 } 2865 }
2866 2866
2867 2867
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2913 return ToBoolean(v8_isolate->GetCurrentContext()).ToLocalChecked(); 2913 return ToBoolean(v8_isolate->GetCurrentContext()).ToLocalChecked();
2914 } 2914 }
2915 2915
2916 2916
2917 MaybeLocal<Number> Value::ToNumber(Local<Context> context) const { 2917 MaybeLocal<Number> Value::ToNumber(Local<Context> context) const {
2918 auto obj = Utils::OpenHandle(this); 2918 auto obj = Utils::OpenHandle(this);
2919 if (obj->IsNumber()) return ToApiHandle<Number>(obj); 2919 if (obj->IsNumber()) return ToApiHandle<Number>(obj);
2920 PREPARE_FOR_EXECUTION(context, "ToNumber", Number); 2920 PREPARE_FOR_EXECUTION(context, "ToNumber", Number);
2921 Local<Number> result; 2921 Local<Number> result;
2922 has_pending_exception = 2922 has_pending_exception =
2923 !ToLocal<Number>(i::Execution::ToNumber(isolate, obj), &result); 2923 !ToLocal<Number>(i::Object::ToNumber(isolate, obj), &result);
2924 RETURN_ON_FAILED_EXECUTION(Number); 2924 RETURN_ON_FAILED_EXECUTION(Number);
2925 RETURN_ESCAPED(result); 2925 RETURN_ESCAPED(result);
2926 } 2926 }
2927 2927
2928 2928
2929 Local<Number> Value::ToNumber(Isolate* isolate) const { 2929 Local<Number> Value::ToNumber(Isolate* isolate) const {
2930 RETURN_TO_LOCAL_UNCHECKED(ToNumber(isolate->GetCurrentContext()), Number); 2930 RETURN_TO_LOCAL_UNCHECKED(ToNumber(isolate->GetCurrentContext()), Number);
2931 } 2931 }
2932 2932
2933 2933
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
3237 bool Value::BooleanValue() const { 3237 bool Value::BooleanValue() const {
3238 return Utils::OpenHandle(this)->BooleanValue(); 3238 return Utils::OpenHandle(this)->BooleanValue();
3239 } 3239 }
3240 3240
3241 3241
3242 Maybe<double> Value::NumberValue(Local<Context> context) const { 3242 Maybe<double> Value::NumberValue(Local<Context> context) const {
3243 auto obj = Utils::OpenHandle(this); 3243 auto obj = Utils::OpenHandle(this);
3244 if (obj->IsNumber()) return Just(obj->Number()); 3244 if (obj->IsNumber()) return Just(obj->Number());
3245 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "NumberValue", double); 3245 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "NumberValue", double);
3246 i::Handle<i::Object> num; 3246 i::Handle<i::Object> num;
3247 has_pending_exception = !i::Execution::ToNumber(isolate, obj).ToHandle(&num); 3247 has_pending_exception = !i::Object::ToNumber(isolate, obj).ToHandle(&num);
3248 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(double); 3248 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(double);
3249 return Just(num->Number()); 3249 return Just(num->Number());
3250 } 3250 }
3251 3251
3252 3252
3253 double Value::NumberValue() const { 3253 double Value::NumberValue() const {
3254 auto obj = Utils::OpenHandle(this); 3254 auto obj = Utils::OpenHandle(this);
3255 if (obj->IsNumber()) return obj->Number(); 3255 if (obj->IsNumber()) return obj->Number();
3256 return NumberValue(ContextFromHeapObject(obj)) 3256 return NumberValue(ContextFromHeapObject(obj))
3257 .FromMaybe(std::numeric_limits<double>::quiet_NaN()); 3257 .FromMaybe(std::numeric_limits<double>::quiet_NaN());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
3327 3327
3328 MaybeLocal<Uint32> Value::ToArrayIndex(Local<Context> context) const { 3328 MaybeLocal<Uint32> Value::ToArrayIndex(Local<Context> context) const {
3329 auto self = Utils::OpenHandle(this); 3329 auto self = Utils::OpenHandle(this);
3330 if (self->IsSmi()) { 3330 if (self->IsSmi()) {
3331 if (i::Smi::cast(*self)->value() >= 0) return Utils::Uint32ToLocal(self); 3331 if (i::Smi::cast(*self)->value() >= 0) return Utils::Uint32ToLocal(self);
3332 return Local<Uint32>(); 3332 return Local<Uint32>();
3333 } 3333 }
3334 PREPARE_FOR_EXECUTION(context, "ToArrayIndex", Uint32); 3334 PREPARE_FOR_EXECUTION(context, "ToArrayIndex", Uint32);
3335 i::Handle<i::Object> string_obj; 3335 i::Handle<i::Object> string_obj;
3336 has_pending_exception = 3336 has_pending_exception =
3337 !i::Execution::ToString(isolate, self).ToHandle(&string_obj); 3337 !i::Object::ToString(isolate, self).ToHandle(&string_obj);
3338 RETURN_ON_FAILED_EXECUTION(Uint32); 3338 RETURN_ON_FAILED_EXECUTION(Uint32);
3339 i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj); 3339 i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj);
3340 uint32_t index; 3340 uint32_t index;
3341 if (str->AsArrayIndex(&index)) { 3341 if (str->AsArrayIndex(&index)) {
3342 i::Handle<i::Object> value; 3342 i::Handle<i::Object> value;
3343 if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) { 3343 if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) {
3344 value = i::Handle<i::Object>(i::Smi::FromInt(index), isolate); 3344 value = i::Handle<i::Object>(i::Smi::FromInt(index), isolate);
3345 } else { 3345 } else {
3346 value = isolate->factory()->NewNumber(index); 3346 value = isolate->factory()->NewNumber(index);
3347 } 3347 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
3607 } 3607 }
3608 3608
3609 3609
3610 Maybe<PropertyAttribute> v8::Object::GetPropertyAttributes( 3610 Maybe<PropertyAttribute> v8::Object::GetPropertyAttributes(
3611 Local<Context> context, Local<Value> key) { 3611 Local<Context> context, Local<Value> key) {
3612 PREPARE_FOR_EXECUTION_PRIMITIVE( 3612 PREPARE_FOR_EXECUTION_PRIMITIVE(
3613 context, "v8::Object::GetPropertyAttributes()", PropertyAttribute); 3613 context, "v8::Object::GetPropertyAttributes()", PropertyAttribute);
3614 auto self = Utils::OpenHandle(this); 3614 auto self = Utils::OpenHandle(this);
3615 auto key_obj = Utils::OpenHandle(*key); 3615 auto key_obj = Utils::OpenHandle(*key);
3616 if (!key_obj->IsName()) { 3616 if (!key_obj->IsName()) {
3617 has_pending_exception = !i::Execution::ToString( 3617 has_pending_exception =
3618 isolate, key_obj).ToHandle(&key_obj); 3618 !i::Object::ToString(isolate, key_obj).ToHandle(&key_obj);
3619 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute); 3619 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute);
3620 } 3620 }
3621 auto key_name = i::Handle<i::Name>::cast(key_obj); 3621 auto key_name = i::Handle<i::Name>::cast(key_obj);
3622 auto result = i::JSReceiver::GetPropertyAttributes(self, key_name); 3622 auto result = i::JSReceiver::GetPropertyAttributes(self, key_name);
3623 has_pending_exception = result.IsNothing(); 3623 has_pending_exception = result.IsNothing();
3624 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute); 3624 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute);
3625 if (result.FromJust() == ABSENT) { 3625 if (result.FromJust() == ABSENT) {
3626 return Just(static_cast<PropertyAttribute>(NONE)); 3626 return Just(static_cast<PropertyAttribute>(NONE));
3627 } 3627 }
3628 return Just(static_cast<PropertyAttribute>(result.FromJust())); 3628 return Just(static_cast<PropertyAttribute>(result.FromJust()));
(...skipping 4779 matching lines...) Expand 10 before | Expand all | Expand 10 after
8408 Address callback_address = 8408 Address callback_address =
8409 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8409 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8410 VMState<EXTERNAL> state(isolate); 8410 VMState<EXTERNAL> state(isolate);
8411 ExternalCallbackScope call_scope(isolate, callback_address); 8411 ExternalCallbackScope call_scope(isolate, callback_address);
8412 callback(info); 8412 callback(info);
8413 } 8413 }
8414 8414
8415 8415
8416 } // namespace internal 8416 } // namespace internal
8417 } // namespace v8 8417 } // namespace v8
OLDNEW
« no previous file with comments | « src/accessors.cc ('k') | src/arm/code-stubs-arm.cc » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698