OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); | 98 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); |
99 Context* native_context = isolate->context()->native_context(); | 99 Context* native_context = isolate->context()->native_context(); |
100 return CreateJSValue(native_context->string_function(), this); | 100 return CreateJSValue(native_context->string_function(), this); |
101 } | 101 } |
102 | 102 |
103 // Throw a type error. | 103 // Throw a type error. |
104 return Failure::InternalError(); | 104 return Failure::InternalError(); |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 Object* Object::ToBoolean() { | 108 bool Object::BooleanValue() { |
109 if (IsTrue()) return this; | 109 if (IsBoolean()) return IsTrue(); |
110 if (IsFalse()) return this; | 110 if (IsSmi()) return Smi::cast(this)->value() != 0; |
111 if (IsSmi()) { | 111 if (IsUndefined() || IsNull()) return false; |
112 return Isolate::Current()->heap()->ToBoolean(Smi::cast(this)->value() != 0); | 112 if (IsUndetectableObject()) return false; // Undetectable object is false. |
113 } | 113 if (IsString()) return String::cast(this)->length() != 0; |
114 HeapObject* heap_object = HeapObject::cast(this); | 114 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); |
115 if (heap_object->IsUndefined() || heap_object->IsNull()) { | 115 return true; |
116 return heap_object->GetHeap()->false_value(); | |
117 } | |
118 // Undetectable object is false | |
119 if (heap_object->IsUndetectableObject()) { | |
120 return heap_object->GetHeap()->false_value(); | |
121 } | |
122 if (heap_object->IsString()) { | |
123 return heap_object->GetHeap()->ToBoolean( | |
124 String::cast(this)->length() != 0); | |
125 } | |
126 if (heap_object->IsHeapNumber()) { | |
127 return HeapNumber::cast(this)->HeapNumberToBoolean(); | |
128 } | |
129 return heap_object->GetHeap()->true_value(); | |
130 } | 116 } |
131 | 117 |
132 | 118 |
133 void Object::Lookup(Name* name, LookupResult* result) { | 119 void Object::Lookup(Name* name, LookupResult* result) { |
134 Object* holder = NULL; | 120 Object* holder = NULL; |
135 if (IsJSReceiver()) { | 121 if (IsJSReceiver()) { |
136 holder = this; | 122 holder = this; |
137 } else { | 123 } else { |
138 Context* native_context = result->isolate()->context()->native_context(); | 124 Context* native_context = result->isolate()->context()->native_context(); |
139 if (IsNumber()) { | 125 if (IsNumber()) { |
(...skipping 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 #undef MAKE_STRUCT_CASE | 1606 #undef MAKE_STRUCT_CASE |
1621 StructBodyDescriptor::IterateBody(this, object_size, v); | 1607 StructBodyDescriptor::IterateBody(this, object_size, v); |
1622 break; | 1608 break; |
1623 default: | 1609 default: |
1624 PrintF("Unknown type: %d\n", type); | 1610 PrintF("Unknown type: %d\n", type); |
1625 UNREACHABLE(); | 1611 UNREACHABLE(); |
1626 } | 1612 } |
1627 } | 1613 } |
1628 | 1614 |
1629 | 1615 |
1630 Object* HeapNumber::HeapNumberToBoolean() { | 1616 bool HeapNumber::HeapNumberBooleanValue() { |
1631 // NaN, +0, and -0 should return the false object | 1617 // NaN, +0, and -0 should return the false object |
1632 #if __BYTE_ORDER == __LITTLE_ENDIAN | 1618 #if __BYTE_ORDER == __LITTLE_ENDIAN |
1633 union IeeeDoubleLittleEndianArchType u; | 1619 union IeeeDoubleLittleEndianArchType u; |
1634 #elif __BYTE_ORDER == __BIG_ENDIAN | 1620 #elif __BYTE_ORDER == __BIG_ENDIAN |
1635 union IeeeDoubleBigEndianArchType u; | 1621 union IeeeDoubleBigEndianArchType u; |
1636 #endif | 1622 #endif |
1637 u.d = value(); | 1623 u.d = value(); |
1638 if (u.bits.exp == 2047) { | 1624 if (u.bits.exp == 2047) { |
1639 // Detect NaN for IEEE double precision floating point. | 1625 // Detect NaN for IEEE double precision floating point. |
1640 if ((u.bits.man_low | u.bits.man_high) != 0) | 1626 if ((u.bits.man_low | u.bits.man_high) != 0) return false; |
1641 return GetHeap()->false_value(); | |
1642 } | 1627 } |
1643 if (u.bits.exp == 0) { | 1628 if (u.bits.exp == 0) { |
1644 // Detect +0, and -0 for IEEE double precision floating point. | 1629 // Detect +0, and -0 for IEEE double precision floating point. |
1645 if ((u.bits.man_low | u.bits.man_high) == 0) | 1630 if ((u.bits.man_low | u.bits.man_high) == 0) return false; |
1646 return GetHeap()->false_value(); | |
1647 } | 1631 } |
1648 return GetHeap()->true_value(); | 1632 return true; |
1649 } | 1633 } |
1650 | 1634 |
1651 | 1635 |
1652 void HeapNumber::HeapNumberPrint(FILE* out) { | 1636 void HeapNumber::HeapNumberPrint(FILE* out) { |
1653 PrintF(out, "%.16g", Number()); | 1637 PrintF(out, "%.16g", Number()); |
1654 } | 1638 } |
1655 | 1639 |
1656 | 1640 |
1657 void HeapNumber::HeapNumberPrint(StringStream* accumulator) { | 1641 void HeapNumber::HeapNumberPrint(StringStream* accumulator) { |
1658 // The Windows version of vsnprintf can allocate when printing a %g string | 1642 // The Windows version of vsnprintf can allocate when printing a %g string |
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2771 Isolate* isolate = GetIsolate(); | 2755 Isolate* isolate = GetIsolate(); |
2772 HandleScope scope(isolate); | 2756 HandleScope scope(isolate); |
2773 Handle<Object> receiver(this, isolate); | 2757 Handle<Object> receiver(this, isolate); |
2774 Handle<Object> name(name_raw, isolate); | 2758 Handle<Object> name(name_raw, isolate); |
2775 | 2759 |
2776 Handle<Object> args[] = { name }; | 2760 Handle<Object> args[] = { name }; |
2777 Handle<Object> result = CallTrap( | 2761 Handle<Object> result = CallTrap( |
2778 "has", isolate->derived_has_trap(), ARRAY_SIZE(args), args); | 2762 "has", isolate->derived_has_trap(), ARRAY_SIZE(args), args); |
2779 if (isolate->has_pending_exception()) return false; | 2763 if (isolate->has_pending_exception()) return false; |
2780 | 2764 |
2781 return result->ToBoolean()->IsTrue(); | 2765 return result->BooleanValue(); |
2782 } | 2766 } |
2783 | 2767 |
2784 | 2768 |
2785 MUST_USE_RESULT MaybeObject* JSProxy::SetPropertyWithHandler( | 2769 MUST_USE_RESULT MaybeObject* JSProxy::SetPropertyWithHandler( |
2786 JSReceiver* receiver_raw, | 2770 JSReceiver* receiver_raw, |
2787 Name* name_raw, | 2771 Name* name_raw, |
2788 Object* value_raw, | 2772 Object* value_raw, |
2789 PropertyAttributes attributes, | 2773 PropertyAttributes attributes, |
2790 StrictModeFlag strict_mode) { | 2774 StrictModeFlag strict_mode) { |
2791 Isolate* isolate = GetIsolate(); | 2775 Isolate* isolate = GetIsolate(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2903 Isolate* isolate = GetIsolate(); | 2887 Isolate* isolate = GetIsolate(); |
2904 HandleScope scope(isolate); | 2888 HandleScope scope(isolate); |
2905 Handle<JSProxy> receiver(this); | 2889 Handle<JSProxy> receiver(this); |
2906 Handle<Object> name(name_raw, isolate); | 2890 Handle<Object> name(name_raw, isolate); |
2907 | 2891 |
2908 Handle<Object> args[] = { name }; | 2892 Handle<Object> args[] = { name }; |
2909 Handle<Object> result = CallTrap( | 2893 Handle<Object> result = CallTrap( |
2910 "delete", Handle<Object>(), ARRAY_SIZE(args), args); | 2894 "delete", Handle<Object>(), ARRAY_SIZE(args), args); |
2911 if (isolate->has_pending_exception()) return Failure::Exception(); | 2895 if (isolate->has_pending_exception()) return Failure::Exception(); |
2912 | 2896 |
2913 Object* bool_result = result->ToBoolean(); | 2897 bool result_bool = result->BooleanValue(); |
2914 if (mode == STRICT_DELETION && bool_result == GetHeap()->false_value()) { | 2898 if (mode == STRICT_DELETION && !result_bool) { |
2915 Handle<Object> handler(receiver->handler(), isolate); | 2899 Handle<Object> handler(receiver->handler(), isolate); |
2916 Handle<String> trap_name = isolate->factory()->InternalizeOneByteString( | 2900 Handle<String> trap_name = isolate->factory()->InternalizeOneByteString( |
2917 STATIC_ASCII_VECTOR("delete")); | 2901 STATIC_ASCII_VECTOR("delete")); |
2918 Handle<Object> args[] = { handler, trap_name }; | 2902 Handle<Object> args[] = { handler, trap_name }; |
2919 Handle<Object> error = isolate->factory()->NewTypeError( | 2903 Handle<Object> error = isolate->factory()->NewTypeError( |
2920 "handler_failed", HandleVector(args, ARRAY_SIZE(args))); | 2904 "handler_failed", HandleVector(args, ARRAY_SIZE(args))); |
2921 isolate->Throw(*error); | 2905 isolate->Throw(*error); |
2922 return Failure::Exception(); | 2906 return Failure::Exception(); |
2923 } | 2907 } |
2924 return bool_result; | 2908 return isolate->heap()->ToBoolean(result_bool); |
2925 } | 2909 } |
2926 | 2910 |
2927 | 2911 |
2928 MUST_USE_RESULT MaybeObject* JSProxy::DeleteElementWithHandler( | 2912 MUST_USE_RESULT MaybeObject* JSProxy::DeleteElementWithHandler( |
2929 uint32_t index, | 2913 uint32_t index, |
2930 DeleteMode mode) { | 2914 DeleteMode mode) { |
2931 Isolate* isolate = GetIsolate(); | 2915 Isolate* isolate = GetIsolate(); |
2932 HandleScope scope(isolate); | 2916 HandleScope scope(isolate); |
2933 Handle<String> name = isolate->factory()->Uint32ToString(index); | 2917 Handle<String> name = isolate->factory()->Uint32ToString(index); |
2934 return JSProxy::DeletePropertyWithHandler(*name, mode); | 2918 return JSProxy::DeletePropertyWithHandler(*name, mode); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2977 Handle<String> trap = isolate->factory()->InternalizeOneByteString( | 2961 Handle<String> trap = isolate->factory()->InternalizeOneByteString( |
2978 STATIC_ASCII_VECTOR("getPropertyDescriptor")); | 2962 STATIC_ASCII_VECTOR("getPropertyDescriptor")); |
2979 Handle<Object> args[] = { handler, trap, name }; | 2963 Handle<Object> args[] = { handler, trap, name }; |
2980 Handle<Object> error = isolate->factory()->NewTypeError( | 2964 Handle<Object> error = isolate->factory()->NewTypeError( |
2981 "proxy_prop_not_configurable", HandleVector(args, ARRAY_SIZE(args))); | 2965 "proxy_prop_not_configurable", HandleVector(args, ARRAY_SIZE(args))); |
2982 isolate->Throw(*error); | 2966 isolate->Throw(*error); |
2983 return NONE; | 2967 return NONE; |
2984 } | 2968 } |
2985 | 2969 |
2986 int attributes = NONE; | 2970 int attributes = NONE; |
2987 if (enumerable->ToBoolean()->IsFalse()) attributes |= DONT_ENUM; | 2971 if (!enumerable->BooleanValue()) attributes |= DONT_ENUM; |
2988 if (configurable->ToBoolean()->IsFalse()) attributes |= DONT_DELETE; | 2972 if (!configurable->BooleanValue()) attributes |= DONT_DELETE; |
2989 if (writable->ToBoolean()->IsFalse()) attributes |= READ_ONLY; | 2973 if (!writable->BooleanValue()) attributes |= READ_ONLY; |
2990 return static_cast<PropertyAttributes>(attributes); | 2974 return static_cast<PropertyAttributes>(attributes); |
2991 } | 2975 } |
2992 | 2976 |
2993 | 2977 |
2994 MUST_USE_RESULT PropertyAttributes JSProxy::GetElementAttributeWithHandler( | 2978 MUST_USE_RESULT PropertyAttributes JSProxy::GetElementAttributeWithHandler( |
2995 JSReceiver* receiver_raw, | 2979 JSReceiver* receiver_raw, |
2996 uint32_t index) { | 2980 uint32_t index) { |
2997 Isolate* isolate = GetIsolate(); | 2981 Isolate* isolate = GetIsolate(); |
2998 HandleScope scope(isolate); | 2982 HandleScope scope(isolate); |
2999 Handle<JSProxy> proxy(this); | 2983 Handle<JSProxy> proxy(this); |
(...skipping 11295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14295 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 14279 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
14296 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 14280 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
14297 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 14281 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
14298 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 14282 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
14299 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 14283 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
14300 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 14284 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
14301 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 14285 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
14302 } | 14286 } |
14303 | 14287 |
14304 } } // namespace v8::internal | 14288 } } // namespace v8::internal |
OLD | NEW |