| 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 Handle<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 { |
| 75 ASSERT(object->IsSymbol()); |
| 76 constructor = handle(native_context->symbol_function(), isolate); |
| 70 } | 77 } |
| 71 JSValue::cast(result)->set_value(value); | 78 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor); |
| 79 Handle<JSValue>::cast(result)->set_value(*object); |
| 72 return result; | 80 return result; |
| 73 } | 81 } |
| 74 | 82 |
| 75 | 83 |
| 76 MaybeObject* Object::ToObject(Context* native_context) { | |
| 77 if (IsNumber()) { | |
| 78 return CreateJSValue(native_context->number_function(), this); | |
| 79 } else if (IsBoolean()) { | |
| 80 return CreateJSValue(native_context->boolean_function(), this); | |
| 81 } else if (IsString()) { | |
| 82 return CreateJSValue(native_context->string_function(), this); | |
| 83 } else if (IsSymbol()) { | |
| 84 return CreateJSValue(native_context->symbol_function(), this); | |
| 85 } | |
| 86 ASSERT(IsJSObject()); | |
| 87 return this; | |
| 88 } | |
| 89 | |
| 90 | |
| 91 MaybeObject* Object::ToObject(Isolate* isolate) { | |
| 92 if (IsJSReceiver()) { | |
| 93 return this; | |
| 94 } else if (IsNumber()) { | |
| 95 Context* native_context = isolate->context()->native_context(); | |
| 96 return CreateJSValue(native_context->number_function(), this); | |
| 97 } else if (IsBoolean()) { | |
| 98 Context* native_context = isolate->context()->native_context(); | |
| 99 return CreateJSValue(native_context->boolean_function(), this); | |
| 100 } else if (IsString()) { | |
| 101 Context* native_context = isolate->context()->native_context(); | |
| 102 return CreateJSValue(native_context->string_function(), this); | |
| 103 } else if (IsSymbol()) { | |
| 104 Context* native_context = isolate->context()->native_context(); | |
| 105 return CreateJSValue(native_context->symbol_function(), this); | |
| 106 } | |
| 107 | |
| 108 // Throw a type error. | |
| 109 return Failure::InternalError(); | |
| 110 } | |
| 111 | |
| 112 | |
| 113 bool Object::BooleanValue() { | 84 bool Object::BooleanValue() { |
| 114 if (IsBoolean()) return IsTrue(); | 85 if (IsBoolean()) return IsTrue(); |
| 115 if (IsSmi()) return Smi::cast(this)->value() != 0; | 86 if (IsSmi()) return Smi::cast(this)->value() != 0; |
| 116 if (IsUndefined() || IsNull()) return false; | 87 if (IsUndefined() || IsNull()) return false; |
| 117 if (IsUndetectableObject()) return false; // Undetectable object is false. | 88 if (IsUndetectableObject()) return false; // Undetectable object is false. |
| 118 if (IsString()) return String::cast(this)->length() != 0; | 89 if (IsString()) return String::cast(this)->length() != 0; |
| 119 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); | 90 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); |
| 120 return true; | 91 return true; |
| 121 } | 92 } |
| 122 | 93 |
| (...skipping 16394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16517 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16488 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16518 static const char* error_messages_[] = { | 16489 static const char* error_messages_[] = { |
| 16519 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16490 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16520 }; | 16491 }; |
| 16521 #undef ERROR_MESSAGES_TEXTS | 16492 #undef ERROR_MESSAGES_TEXTS |
| 16522 return error_messages_[reason]; | 16493 return error_messages_[reason]; |
| 16523 } | 16494 } |
| 16524 | 16495 |
| 16525 | 16496 |
| 16526 } } // namespace v8::internal | 16497 } } // namespace v8::internal |
| OLD | NEW |