| Index: src/objects.cc
|
| diff --git a/src/objects.cc b/src/objects.cc
|
| index dae7d51b6a1195117f87dcc108944324a1701cc7..7d2ce58fb598219bde6dfc4d46c2aaf73e947cf6 100644
|
| --- a/src/objects.cc
|
| +++ b/src/objects.cc
|
| @@ -60,15 +60,24 @@
|
| namespace v8 {
|
| namespace internal {
|
|
|
| -
|
| -MUST_USE_RESULT static MaybeObject* CreateJSValue(JSFunction* constructor,
|
| - Object* value) {
|
| - Object* result;
|
| - { MaybeObject* maybe_result =
|
| - constructor->GetHeap()->AllocateJSObject(constructor);
|
| - if (!maybe_result->ToObject(&result)) return maybe_result;
|
| +MaybeHandle<JSReceiver> Object::ToObject(Isolate* isolate,
|
| + Handle<Object> object,
|
| + Handle<Context> native_context) {
|
| + if (object->IsJSReceiver()) return Handle<JSReceiver>::cast(object);
|
| + Handle<JSFunction> constructor;
|
| + if (object->IsNumber()) {
|
| + constructor = handle(native_context->number_function(), isolate);
|
| + } else if (object->IsBoolean()) {
|
| + constructor = handle(native_context->boolean_function(), isolate);
|
| + } else if (object->IsString()) {
|
| + constructor = handle(native_context->string_function(), isolate);
|
| + } else if (object->IsSymbol()) {
|
| + constructor = handle(native_context->symbol_function(), isolate);
|
| + } else {
|
| + return MaybeHandle<JSReceiver>();
|
| }
|
| - JSValue::cast(result)->set_value(value);
|
| + Handle<JSObject> result = isolate->factory()->NewJSObject(constructor);
|
| + Handle<JSValue>::cast(result)->set_value(*object);
|
| return result;
|
| }
|
|
|
| @@ -90,43 +99,6 @@ Handle<HeapType> Object::OptimalType(Isolate* isolate,
|
| }
|
|
|
|
|
| -MaybeObject* Object::ToObject(Context* native_context) {
|
| - if (IsNumber()) {
|
| - return CreateJSValue(native_context->number_function(), this);
|
| - } else if (IsBoolean()) {
|
| - return CreateJSValue(native_context->boolean_function(), this);
|
| - } else if (IsString()) {
|
| - return CreateJSValue(native_context->string_function(), this);
|
| - } else if (IsSymbol()) {
|
| - return CreateJSValue(native_context->symbol_function(), this);
|
| - }
|
| - ASSERT(IsJSObject());
|
| - return this;
|
| -}
|
| -
|
| -
|
| -MaybeObject* Object::ToObject(Isolate* isolate) {
|
| - if (IsJSReceiver()) {
|
| - return this;
|
| - } else if (IsNumber()) {
|
| - Context* native_context = isolate->context()->native_context();
|
| - return CreateJSValue(native_context->number_function(), this);
|
| - } else if (IsBoolean()) {
|
| - Context* native_context = isolate->context()->native_context();
|
| - return CreateJSValue(native_context->boolean_function(), this);
|
| - } else if (IsString()) {
|
| - Context* native_context = isolate->context()->native_context();
|
| - return CreateJSValue(native_context->string_function(), this);
|
| - } else if (IsSymbol()) {
|
| - Context* native_context = isolate->context()->native_context();
|
| - return CreateJSValue(native_context->symbol_function(), this);
|
| - }
|
| -
|
| - // Throw a type error.
|
| - return Failure::InternalError();
|
| -}
|
| -
|
| -
|
| bool Object::BooleanValue() {
|
| if (IsBoolean()) return IsTrue();
|
| if (IsSmi()) return Smi::cast(this)->value() != 0;
|
|
|