| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #include "utils.h" | 53 #include "utils.h" |
| 54 | 54 |
| 55 #ifdef ENABLE_DISASSEMBLER | 55 #ifdef ENABLE_DISASSEMBLER |
| 56 #include "disasm.h" | 56 #include "disasm.h" |
| 57 #include "disassembler.h" | 57 #include "disassembler.h" |
| 58 #endif | 58 #endif |
| 59 | 59 |
| 60 namespace v8 { | 60 namespace v8 { |
| 61 namespace internal { | 61 namespace internal { |
| 62 | 62 |
| 63 | 63 MaybeHandle<JSReceiver> Object::ToObject(Isolate* isolate, |
| 64 MUST_USE_RESULT static MaybeObject* CreateJSValue(JSFunction* constructor, | 64 Handle<Object> object, |
| 65 Object* value) { | 65 Handle<Context> native_context) { |
| 66 Object* result; | 66 if (object->IsJSReceiver()) return Handle<JSReceiver>::cast(object); |
| 67 { MaybeObject* maybe_result = | 67 Handle<JSFunction> constructor; |
| 68 constructor->GetHeap()->AllocateJSObject(constructor); | 68 if (object->IsNumber()) { |
| 69 if (!maybe_result->ToObject(&result)) return maybe_result; | 69 constructor = handle(native_context->number_function(), isolate); |
| 70 } else if (object->IsBoolean()) { |
| 71 constructor = handle(native_context->boolean_function(), isolate); |
| 72 } else if (object->IsString()) { |
| 73 constructor = handle(native_context->string_function(), isolate); |
| 74 } else if (object->IsSymbol()) { |
| 75 constructor = handle(native_context->symbol_function(), isolate); |
| 76 } else { |
| 77 return MaybeHandle<JSReceiver>(); |
| 70 } | 78 } |
| 71 JSValue::cast(result)->set_value(value); | 79 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor); |
| 80 Handle<JSValue>::cast(result)->set_value(*object); |
| 72 return result; | 81 return result; |
| 73 } | 82 } |
| 74 | 83 |
| 75 | 84 |
| 76 Handle<HeapType> Object::OptimalType(Isolate* isolate, | 85 Handle<HeapType> Object::OptimalType(Isolate* isolate, |
| 77 Representation representation) { | 86 Representation representation) { |
| 78 if (!FLAG_track_field_types) return HeapType::Any(isolate); | 87 if (!FLAG_track_field_types) return HeapType::Any(isolate); |
| 79 if (representation.IsNone()) return HeapType::None(isolate); | 88 if (representation.IsNone()) return HeapType::None(isolate); |
| 80 if (representation.IsHeapObject() && IsHeapObject()) { | 89 if (representation.IsHeapObject() && IsHeapObject()) { |
| 81 // We can track only JavaScript objects with stable maps. | 90 // We can track only JavaScript objects with stable maps. |
| 82 Handle<Map> map(HeapObject::cast(this)->map(), isolate); | 91 Handle<Map> map(HeapObject::cast(this)->map(), isolate); |
| 83 if (map->is_stable() && | 92 if (map->is_stable() && |
| 84 map->instance_type() >= FIRST_NONCALLABLE_SPEC_OBJECT_TYPE && | 93 map->instance_type() >= FIRST_NONCALLABLE_SPEC_OBJECT_TYPE && |
| 85 map->instance_type() <= LAST_NONCALLABLE_SPEC_OBJECT_TYPE) { | 94 map->instance_type() <= LAST_NONCALLABLE_SPEC_OBJECT_TYPE) { |
| 86 return HeapType::Class(map, isolate); | 95 return HeapType::Class(map, isolate); |
| 87 } | 96 } |
| 88 } | 97 } |
| 89 return HeapType::Any(isolate); | 98 return HeapType::Any(isolate); |
| 90 } | 99 } |
| 91 | 100 |
| 92 | 101 |
| 93 MaybeObject* Object::ToObject(Context* native_context) { | |
| 94 if (IsNumber()) { | |
| 95 return CreateJSValue(native_context->number_function(), this); | |
| 96 } else if (IsBoolean()) { | |
| 97 return CreateJSValue(native_context->boolean_function(), this); | |
| 98 } else if (IsString()) { | |
| 99 return CreateJSValue(native_context->string_function(), this); | |
| 100 } else if (IsSymbol()) { | |
| 101 return CreateJSValue(native_context->symbol_function(), this); | |
| 102 } | |
| 103 ASSERT(IsJSObject()); | |
| 104 return this; | |
| 105 } | |
| 106 | |
| 107 | |
| 108 MaybeObject* Object::ToObject(Isolate* isolate) { | |
| 109 if (IsJSReceiver()) { | |
| 110 return this; | |
| 111 } else if (IsNumber()) { | |
| 112 Context* native_context = isolate->context()->native_context(); | |
| 113 return CreateJSValue(native_context->number_function(), this); | |
| 114 } else if (IsBoolean()) { | |
| 115 Context* native_context = isolate->context()->native_context(); | |
| 116 return CreateJSValue(native_context->boolean_function(), this); | |
| 117 } else if (IsString()) { | |
| 118 Context* native_context = isolate->context()->native_context(); | |
| 119 return CreateJSValue(native_context->string_function(), this); | |
| 120 } else if (IsSymbol()) { | |
| 121 Context* native_context = isolate->context()->native_context(); | |
| 122 return CreateJSValue(native_context->symbol_function(), this); | |
| 123 } | |
| 124 | |
| 125 // Throw a type error. | |
| 126 return Failure::InternalError(); | |
| 127 } | |
| 128 | |
| 129 | |
| 130 bool Object::BooleanValue() { | 102 bool Object::BooleanValue() { |
| 131 if (IsBoolean()) return IsTrue(); | 103 if (IsBoolean()) return IsTrue(); |
| 132 if (IsSmi()) return Smi::cast(this)->value() != 0; | 104 if (IsSmi()) return Smi::cast(this)->value() != 0; |
| 133 if (IsUndefined() || IsNull()) return false; | 105 if (IsUndefined() || IsNull()) return false; |
| 134 if (IsUndetectableObject()) return false; // Undetectable object is false. | 106 if (IsUndetectableObject()) return false; // Undetectable object is false. |
| 135 if (IsString()) return String::cast(this)->length() != 0; | 107 if (IsString()) return String::cast(this)->length() != 0; |
| 136 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); | 108 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); |
| 137 return true; | 109 return true; |
| 138 } | 110 } |
| 139 | 111 |
| (...skipping 16580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16720 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16692 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16721 static const char* error_messages_[] = { | 16693 static const char* error_messages_[] = { |
| 16722 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16694 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16723 }; | 16695 }; |
| 16724 #undef ERROR_MESSAGES_TEXTS | 16696 #undef ERROR_MESSAGES_TEXTS |
| 16725 return error_messages_[reason]; | 16697 return error_messages_[reason]; |
| 16726 } | 16698 } |
| 16727 | 16699 |
| 16728 | 16700 |
| 16729 } } // namespace v8::internal | 16701 } } // namespace v8::internal |
| OLD | NEW |