}
+static Handle<Object> ElementsAccessorSetLengthWrapper(
+ Isolate* isolate,
+ ElementsAccessor* accessor,
+ Handle<JSArray> array,
+ int new_length) {
+ CALL_HEAP_FUNCTION(isolate,
+ accessor->SetLength(*array, Smi::FromInt(new_length)),
+ Object);
+}
+
+
BUILTIN(ArrayPop) {
Heap* heap = isolate->heap();
Object* receiver = *args.receiver();
ElementsAccessor* accessor = array->GetElementsAccessor();
int new_length = len - 1;
- MaybeObject* maybe_result;
if (accessor->HasElement(array, array, new_length, elms_obj)) {
- maybe_result = accessor->Get(array, array, new_length, elms_obj);
+ MaybeObject* maybe_result =
+ accessor->Get(array, array, new_length, elms_obj);
+ if (maybe_result->IsFailure()) return maybe_result;
+ MaybeObject* maybe_failure =
+ accessor->SetLength(array, Smi::FromInt(new_length));
+ if (maybe_failure->IsFailure()) return maybe_failure;
+ return maybe_result;
} else {
- maybe_result = array->GetPrototype()->GetElement(isolate, len - 1);
+ // TODO(yangguo): handlify all once ElementsAccessors are handlified.
+ HandleScope scope(isolate);
+ Handle<Object> proto(array->GetPrototype(), isolate);
+ Handle<Object> element = Object::GetElement(isolate, proto, len - 1);
+ RETURN_IF_EMPTY_HANDLE(isolate, element);
+ Handle<JSArray> array_handle(array, isolate);
+ RETURN_IF_EMPTY_HANDLE(isolate,
+ ElementsAccessorSetLengthWrapper(
+ isolate, accessor, array_handle, new_length));
+ return *element;
}
- if (maybe_result->IsFailure()) return maybe_result;
- MaybeObject* maybe_failure =
- accessor->SetLength(array, Smi::FromInt(new_length));
- if (maybe_failure->IsFailure()) return maybe_failure;
- return maybe_result;
}
*p++ = ' ';
space--;
if (space > 0) {
- MaybeObject* maybe_arg = args->GetElement(isolate(), i);
- Handle<String> arg_str(reinterpret_cast<String*>(maybe_arg));
+ Handle<String> arg_str = Handle<String>::cast(
+ Object::GetElement(isolate(), args, i));
+ CHECK_NOT_EMPTY_HANDLE(isolate(), arg_str);
SmartArrayPointer<char> arg = arg_str->ToCString();
Vector<char> v2(p, static_cast<int>(space));
OS::StrNCpy(v2, arg.get(), space);
do { \
ASSERT(!(isolate)->has_pending_exception()); \
CHECK(!(call).is_null()); \
- CHECK(!(isolate)->has_pending_exception()); \
} while (false)
#define RETURN_IF_EMPTY_HANDLE(isolate, call) \
isolate_);
} else {
property = GetProperty(isolate_, object, key);
- if (property.is_null()) return EXCEPTION;
+ RETURN_IF_EMPTY_HANDLE_VALUE(isolate_, property, EXCEPTION);
}
Result result = SerializeProperty(property, comma, key);
if (!comma && result == SUCCESS) comma = true;
property = GetProperty(isolate_, object, key_handle);
}
}
- if (property.is_null()) return EXCEPTION;
+ RETURN_IF_EMPTY_HANDLE_VALUE(isolate_, property, EXCEPTION);
Result result = SerializeProperty(property, comma, key_handle);
if (!comma && result == SUCCESS) comma = true;
if (result >= EXCEPTION) return result;
// Replace "blocked on active" with "replaced on active" status.
for (int i = 0; i < array_len; i++) {
- if (result->GetElement(result->GetIsolate(), i) ==
- Smi::FromInt(LiveEdit::FUNCTION_BLOCKED_ON_ACTIVE_STACK)) {
+ Handle<Object> obj = Object::GetElement(isolate, result, i);
+ CHECK_NOT_EMPTY_HANDLE(isolate, obj);
+ if (*obj == Smi::FromInt(LiveEdit::FUNCTION_BLOCKED_ON_ACTIVE_STACK)) {
Handle<Object> replaced(
Smi::FromInt(LiveEdit::FUNCTION_REPLACED_ON_ACTIVE_STACK), isolate);
SetElementSloppy(result, i, replaced);
void Logger::LogRuntime(Vector<const char> format,
- JSArray* args) {
+ Handle<JSArray> args) {
if (!log_->IsEnabled() || !FLAG_log_runtime) return;
- HandleScope scope(isolate_);
Log::MessageBuilder msg(log_);
for (int i = 0; i < format.length(); i++) {
char c = format[i];
if (c == '%' && i <= format.length() - 2) {
i++;
ASSERT('0' <= format[i] && format[i] <= '9');
- MaybeObject* maybe = args->GetElement(isolate_, format[i] - '0');
- Object* obj;
- if (!maybe->ToObject(&obj)) {
- msg.Append("<exception>");
- continue;
- }
+ Handle<Object> obj = Object::GetElement(isolate_, args, format[i] - '0');
+ // No exception expected when getting an element from an array literal.
+ CHECK_NOT_EMPTY_HANDLE(isolate_, obj);
i++;
switch (format[i]) {
case 's':
- msg.AppendDetailed(String::cast(obj), false);
+ msg.AppendDetailed(String::cast(*obj), false);
break;
case 'S':
- msg.AppendDetailed(String::cast(obj), true);
+ msg.AppendDetailed(String::cast(*obj), true);
break;
case 'r':
- Logger::LogRegExpSource(Handle<JSRegExp>(JSRegExp::cast(obj)));
+ Logger::LogRegExpSource(Handle<JSRegExp>::cast(obj));
break;
case 'x':
- msg.Append("0x%x", Smi::cast(obj)->value());
+ msg.Append("0x%x", Smi::cast(*obj)->value());
break;
case 'i':
- msg.Append("%i", Smi::cast(obj)->value());
+ msg.Append("%i", Smi::cast(*obj)->value());
break;
default:
UNREACHABLE();
void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache);
// Log an event reported from generated code
- void LogRuntime(Vector<const char> format, JSArray* args);
+ void LogRuntime(Vector<const char> format, Handle<JSArray> args);
bool is_logging() {
return is_logging_;
}
-MaybeObject* Object::GetElement(Isolate* isolate, uint32_t index) {
+Handle<Object> Object::GetElement(Isolate* isolate,
+ Handle<Object> object,
+ uint32_t index) {
// GetElement can trigger a getter which can cause allocation.
// This was not always the case. This ASSERT is here to catch
// leftover incorrect uses.
ASSERT(AllowHeapAllocation::IsAllowed());
- return GetElementWithReceiver(isolate, this, index);
+ CALL_HEAP_FUNCTION(isolate,
+ object->GetElementWithReceiver(isolate, *object, index),
+ Object);
}
// method (or somewhere else entirely). Needs more global clean-up.
uint32_t index;
Isolate* isolate = name->GetIsolate();
- if (name->AsArrayIndex(&index))
- return GetElement(isolate, object, index);
+ if (name->AsArrayIndex(&index)) return GetElement(isolate, object, index);
CALL_HEAP_FUNCTION(isolate, object->GetProperty(*name), Object);
}
-Handle<Object> Object::GetElement(Isolate* isolate,
- Handle<Object> object,
- uint32_t index) {
- CALL_HEAP_FUNCTION(isolate, object->GetElement(isolate, index), Object);
-}
-
-
MaybeObject* JSProxy::GetElementWithHandler(Object* receiver,
uint32_t index) {
String* name;
*name != isolate->heap()->hidden_string();
if (is_observed && lookup->IsDataProperty()) {
old_value = Object::GetProperty(object, name);
+ CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
}
// This is a real property that is not read-only, or it is a
object->LocalLookup(*name, &new_lookup, true);
if (new_lookup.IsDataProperty()) {
Handle<Object> new_value = Object::GetProperty(object, name);
+ CHECK_NOT_EMPTY_HANDLE(isolate, new_value);
if (!new_value->SameValue(*old_value)) {
EnqueueChangeRecord(object, "update", name, old_value);
}
bool is_observed = object->map()->is_observed() &&
*name != isolate->heap()->hidden_string();
if (is_observed && lookup.IsProperty()) {
- if (lookup.IsDataProperty()) old_value =
- Object::GetProperty(object, name);
+ if (lookup.IsDataProperty()) {
+ old_value = Object::GetProperty(object, name);
+ CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
+ }
old_attributes = lookup.GetAttributes();
}
bool value_changed = false;
if (new_lookup.IsDataProperty()) {
Handle<Object> new_value = Object::GetProperty(object, name);
+ CHECK_NOT_EMPTY_HANDLE(isolate, new_value);
value_changed = !old_value->SameValue(*new_value);
}
if (new_lookup.GetAttributes() != old_attributes) {
if (object->map()->is_observed()) {
should_enqueue_change_record = HasLocalElement(object, index);
if (should_enqueue_change_record) {
- old_value = object->GetLocalElementAccessorPair(index) != NULL
- ? Handle<Object>::cast(factory->the_hole_value())
- : Object::GetElement(isolate, object, index);
+ if (object->GetLocalElementAccessorPair(index) != NULL) {
+ old_value = Handle<Object>::cast(factory->the_hole_value());
+ } else {
+ old_value = Object::GetElement(isolate, object, index);
+ CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
+ }
}
}
*name != isolate->heap()->hidden_string();
if (is_observed && lookup.IsDataProperty()) {
old_value = Object::GetProperty(object, name);
+ CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
}
Handle<Object> result;
preexists = HasLocalElement(object, index);
if (preexists && object->GetLocalElementAccessorPair(index) == NULL) {
old_value = Object::GetElement(isolate, object, index);
+ CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
}
} else {
LookupResult lookup(isolate);
preexists = lookup.IsProperty();
if (preexists && lookup.IsDataProperty()) {
old_value = Object::GetProperty(object, name);
+ CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
}
}
}
JSReceiver::GetLocalElementAttribute(object, index);
ASSERT(attributes != ABSENT);
if (attributes == DONT_DELETE) return false;
- old_values->Add(object->GetLocalElementAccessorPair(index) == NULL
- ? Object::GetElement(isolate, object, index)
- : Handle<Object>::cast(isolate->factory()->the_hole_value()));
+ Handle<Object> value;
+ if (object->GetLocalElementAccessorPair(index) != NULL) {
+ value = Handle<Object>::cast(isolate->factory()->the_hole_value());
+ } else {
+ value = Object::GetElement(isolate, object, index);
+ CHECK_NOT_EMPTY_HANDLE(isolate, value);
+ }
+ old_values->Add(value);
indices->Add(index);
return true;
}
Handle<Object> new_length_handle;
if (old_attributes != ABSENT) {
- if (object->GetLocalElementAccessorPair(index) == NULL)
+ if (object->GetLocalElementAccessorPair(index) == NULL) {
old_value = Object::GetElement(isolate, object, index);
+ CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
+ }
} else if (object->IsJSArray()) {
// Store old array length in case adding an element grows the array.
old_length_handle = handle(Handle<JSArray>::cast(object)->length(),
EnqueueChangeRecord(object, "reconfigure", name, old_value);
} else {
Handle<Object> new_value = Object::GetElement(isolate, object, index);
+ CHECK_NOT_EMPTY_HANDLE(isolate, new_value);
bool value_changed = !old_value->SameValue(*new_value);
if (old_attributes != new_attributes) {
if (!value_changed) old_value = isolate->factory()->the_hole_value();
MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver,
JSReceiver* getter);
- static Handle<Object> GetElement(Isolate* isolate,
- Handle<Object> object,
- uint32_t index);
- MUST_USE_RESULT inline MaybeObject* GetElement(Isolate* isolate,
- uint32_t index);
+ static inline Handle<Object> GetElement(Isolate* isolate,
+ Handle<Object> object,
+ uint32_t index);
+
// For use when we know that no exception can be thrown.
inline Object* GetElementNoExceptionThrown(Isolate* isolate, uint32_t index);
MUST_USE_RESULT MaybeObject* GetElementWithReceiver(Isolate* isolate,
if (!result->IsUndefined()) return *result;
}
+ Handle<Object> result;
if (object->IsString() || object->IsNumber() || object->IsBoolean()) {
- return object->GetPrototype(isolate)->GetElement(isolate, index);
+ Handle<Object> proto(object->GetPrototype(isolate), isolate);
+ result = Object::GetElement(isolate, proto, index);
+ } else {
+ result = Object::GetElement(isolate, object, index);
}
-
- return object->GetElement(isolate, index);
+ RETURN_IF_EMPTY_HANDLE(isolate, result);
+ return *result;
}
if (index < n) {
return frame->GetParameter(index);
} else {
- return isolate->initial_object_prototype()->GetElement(isolate, index);
+ Handle<Object> initial_prototype(isolate->initial_object_prototype());
+ Handle<Object> result =
+ Object::GetElement(isolate, initial_prototype, index);
+ RETURN_IF_EMPTY_HANDLE(isolate, result);
+ return *result;
}
}
for (int i = 0; i < argc; ++i) {
argv[i] = Object::GetElement(isolate, arguments, offset + i);
+ RETURN_IF_EMPTY_HANDLE(isolate, argv[i]);
}
bool threw;
Handle<Name> base =
isolate->factory()->NewStringFromAscii(CStrVector("base"));
for (unsigned int i = 0; i < length; ++i) {
- MaybeObject* maybe_string = input->GetElement(isolate, i);
- Object* locale_id;
- if (!maybe_string->ToObject(&locale_id) || !locale_id->IsString()) {
+ Handle<Object> locale_id = Object::GetElement(isolate, input, i);
+ RETURN_IF_EMPTY_HANDLE(isolate, locale_id);
+ if (!locale_id->IsString()) {
return isolate->Throw(isolate->heap()->illegal_argument_string());
}
v8::String::Utf8Value utf8_locale_id(
- v8::Utils::ToLocal(Handle<String>(String::cast(locale_id))));
+ v8::Utils::ToLocal(Handle<String>::cast(locale_id)));
UErrorCode error = U_ZERO_ERROR;
RUNTIME_FUNCTION(MaybeObject*, Runtime_Log) {
- SealHandleScope shs(isolate);
+ HandleScope handle_scope(isolate);
ASSERT(args.length() == 2);
- CONVERT_ARG_CHECKED(String, format, 0);
- CONVERT_ARG_CHECKED(JSArray, elms, 1);
- DisallowHeapAllocation no_gc;
- String::FlatContent format_content = format->GetFlatContent();
- RUNTIME_ASSERT(format_content.IsAscii());
- Vector<const uint8_t> chars = format_content.ToOneByteVector();
- isolate->logger()->LogRuntime(Vector<const char>::cast(chars), elms);
+ CONVERT_ARG_HANDLE_CHECKED(String, format, 0);
+ CONVERT_ARG_HANDLE_CHECKED(JSArray, elms, 1);
+
+ SmartArrayPointer<char> format_chars = format->ToCString();
+ isolate->logger()->LogRuntime(
+ Vector<const char>(format_chars.get(), format->length()), elms);
return isolate->heap()->undefined_value();
}
int expected,
i::Handle<i::Object> obj,
int offset) {
- i::Object* element = obj->GetElement(isolate, offset)->ToObjectChecked();
+ i::Object* element = *i::Object::GetElement(isolate, obj, offset);
CHECK_EQ(expected, i::Smi::cast(element)->value());
}
array_type == v8::kExternalFloat32Array) {
CHECK_EQ(static_cast<int>(i::OS::nan_value()),
static_cast<int>(
- jsobj->GetElement(isolate, 7)->ToObjectChecked()->Number()));
+ i::Object::GetElement(isolate, jsobj, 7)->Number()));
} else {
CheckElementValue(isolate, 0, jsobj, 7);
}
CHECK_EQ(2, result->Int32Value());
CHECK_EQ(2,
static_cast<int>(
- jsobj->GetElement(isolate, 6)->ToObjectChecked()->Number()));
+ i::Object::GetElement(isolate, jsobj, 6)->Number()));
if (array_type != v8::kExternalFloat32Array &&
array_type != v8::kExternalFloat64Array) {
kElementCount);
CHECK_EQ(1,
static_cast<int>(
- jsobj->GetElement(isolate, 1)->ToObjectChecked()->Number()));
+ i::Object::GetElement(isolate, jsobj, 1)->Number()));
ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>(
context.local(), obj, kElementCount, array_type, low, high);
// array[length] = name.
JSReceiver::SetElement(array, 0, name, NONE, SLOPPY);
CHECK_EQ(Smi::FromInt(1), array->length());
- CHECK_EQ(array->GetElement(isolate, 0), *name);
+ CHECK_EQ(*i::Object::GetElement(isolate, array, 0), *name);
// Set array length with larger than smi value.
Handle<Object> length =
uint32_t new_int_length = 0;
CHECK(array->length()->ToArrayIndex(&new_int_length));
CHECK_EQ(static_cast<double>(int_length), new_int_length - 1);
- CHECK_EQ(array->GetElement(isolate, int_length), *name);
- CHECK_EQ(array->GetElement(isolate, 0), *name);
+ CHECK_EQ(*i::Object::GetElement(isolate, array, int_length), *name);
+ CHECK_EQ(*i::Object::GetElement(isolate, array, 0), *name);
}
Handle<JSObject> clone = JSObject::Copy(obj);
CHECK(!clone.is_identical_to(obj));
- CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 0));
- CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 1));
+ CHECK_EQ(*i::Object::GetElement(isolate, obj, 0),
+ *i::Object::GetElement(isolate, clone, 0));
+ CHECK_EQ(*i::Object::GetElement(isolate, obj, 1),
+ *i::Object::GetElement(isolate, clone, 1));
CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first));
CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second));
JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY);
JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY);
- CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 0));
- CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 1));
+ CHECK_EQ(*i::Object::GetElement(isolate, obj, 1),
+ *i::Object::GetElement(isolate, clone, 0));
+ CHECK_EQ(*i::Object::GetElement(isolate, obj, 0),
+ *i::Object::GetElement(isolate, clone, 1));
CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first));
CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second));