LOG_API(i_isolate, "NumberObject::New");
ENTER_V8(i_isolate);
i::Handle<i::Object> number = i_isolate->factory()->NewNumber(value);
- i::Handle<i::Object> obj = i_isolate->factory()->ToObject(number);
+ i::Handle<i::Object> obj =
+ i::Object::ToObject(i_isolate, number).ToHandleChecked();
return Utils::ToLocal(obj);
}
? isolate->heap()->true_value()
: isolate->heap()->false_value(),
isolate);
- i::Handle<i::Object> obj = isolate->factory()->ToObject(boolean);
+ i::Handle<i::Object> obj =
+ i::Object::ToObject(isolate, boolean).ToHandleChecked();
return Utils::ToLocal(obj);
}
EnsureInitializedForIsolate(isolate, "v8::StringObject::New()");
LOG_API(isolate, "StringObject::New");
ENTER_V8(isolate);
- i::Handle<i::Object> obj =
- isolate->factory()->ToObject(Utils::OpenHandle(*value));
+ i::Handle<i::Object> obj = i::Object::ToObject(
+ isolate, Utils::OpenHandle(*value)).ToHandleChecked();
return Utils::ToLocal(obj);
}
EnsureInitializedForIsolate(i_isolate, "v8::SymbolObject::New()");
LOG_API(i_isolate, "SymbolObject::New");
ENTER_V8(i_isolate);
- i::Handle<i::Object> obj =
- i_isolate->factory()->ToObject(Utils::OpenHandle(*value));
+ i::Handle<i::Object> obj = i::Object::ToObject(
+ i_isolate, Utils::OpenHandle(*value)).ToHandleChecked();
return Utils::ToLocal(obj);
}
}
-Handle<Object> Factory::ToObject(Handle<Object> object) {
- CALL_HEAP_FUNCTION(isolate(), object->ToObject(isolate()), Object);
-}
-
-
-Handle<Object> Factory::ToObject(Handle<Object> object,
- Handle<Context> native_context) {
- CALL_HEAP_FUNCTION(isolate(), object->ToObject(*native_context), Object);
-}
-
-
#ifdef ENABLE_DEBUGGER_SUPPORT
Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) {
// Get the original code of the function.
Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
- Handle<Object> ToObject(Handle<Object> object);
- Handle<Object> ToObject(Handle<Object> object,
- Handle<Context> native_context);
-
// Interface for creating error objects.
Handle<Object> NewError(const char* maker, const char* message,
overflowed_(false) {
factory_ = isolate_->factory();
accumulator_store_ = Handle<JSValue>::cast(
- factory_->ToObject(factory_->empty_string()));
+ Object::ToObject(isolate, factory_->empty_string()).ToHandleChecked());
part_length_ = kInitialPartLength;
current_part_ = factory_->NewRawOneByteString(part_length_).ToHandleChecked();
tojson_string_ = factory_->toJSON_string();
}
+MaybeHandle<JSReceiver> Object::ToObject(Isolate* isolate,
+ Handle<Object> object) {
+ return ToObject(
+ isolate, object, handle(isolate->context()->native_context(), isolate));
+}
+
+
bool Object::HasSpecificClassOf(String* name) {
return this->IsJSObject() && (JSObject::cast(this)->class_name() == name);
}
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;
}
-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;
// Convert to a JSObject if needed.
// native_context is used when creating wrapper object.
- MUST_USE_RESULT MaybeObject* ToObject(Context* native_context);
+ static inline MaybeHandle<JSReceiver> ToObject(Isolate* isolate,
+ Handle<Object> object);
+ static MaybeHandle<JSReceiver> ToObject(Isolate* isolate,
+ Handle<Object> object,
+ Handle<Context> context);
// Converts this to a Smi if possible.
// Failure is returned otherwise.
RUNTIME_FUNCTION(MaybeObject*, Runtime_NewSymbolWrapper) {
+ HandleScope scope(isolate);
ASSERT(args.length() == 1);
- CONVERT_ARG_CHECKED(Symbol, symbol, 0);
- return symbol->ToObject(isolate);
+ CONVERT_ARG_HANDLE_CHECKED(Symbol, symbol, 0);
+ return *Object::ToObject(isolate, symbol).ToHandleChecked();
}
RUNTIME_FUNCTION(MaybeObject*, Runtime_NewStringWrapper) {
- SealHandleScope shs(isolate);
+ HandleScope scope(isolate);
ASSERT(args.length() == 1);
- CONVERT_ARG_CHECKED(String, value, 0);
- return value->ToObject(isolate);
+ CONVERT_ARG_HANDLE_CHECKED(String, value, 0);
+ return *Object::ToObject(isolate, value).ToHandleChecked();
}
if (args[0]->IsJSReceiver()) {
extension_object = args.at<JSReceiver>(0);
} else {
- // Convert the object to a proper JavaScript object.
- Handle<Object> object = isolate->factory()->ToObject(args.at<Object>(0));
- if (object.is_null()) {
+ // Try to convert the object to a proper JavaScript object.
+ MaybeHandle<JSReceiver> maybe_object =
+ Object::ToObject(isolate, args.at<Object>(0));
+ if (!maybe_object.ToHandle(&extension_object)) {
Handle<Object> handle = args.at<Object>(0);
Handle<Object> result =
isolate->factory()->NewTypeError("with_expression",
HandleVector(&handle, 1));
return isolate->Throw(*result);
}
- extension_object = Handle<JSReceiver>::cast(object);
}
Handle<JSFunction> function;
ASSERT(!receiver->IsNull());
Context* context = Context::cast(it.frame()->context());
Handle<Context> native_context(Context::cast(context->native_context()));
- receiver = isolate->factory()->ToObject(receiver, native_context);
+ receiver = Object::ToObject(
+ isolate, receiver, native_context).ToHandleChecked();
}
}
details->set(kFrameDetailsReceiverIndex, *receiver);