Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Unified Diff: src/accessors.cc

Issue 238973003: Handlify Object::GetPrototype and (most) callers. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Minor Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/builtins.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/accessors.cc
diff --git a/src/accessors.cc b/src/accessors.cc
index 3030e5d9911317384e3d2ae17470245fae126a24..06c5424ff34c2cbe1fa0934e2c1f35cac86dfe4b 100644
--- a/src/accessors.cc
+++ b/src/accessors.cc
@@ -43,11 +43,13 @@ namespace internal {
template <class C>
-static C* FindInstanceOf(Isolate* isolate, Object* obj) {
- for (Object* cur = obj; !cur->IsNull(); cur = cur->GetPrototype(isolate)) {
- if (Is<C>(cur)) return C::cast(cur);
+static Handle<C> FindInstanceOf(Isolate* isolate, Handle<Object> obj) {
+ for (Handle<Object> cur = obj;
+ !cur->IsNull();
+ cur = Object::GetPrototype(isolate, cur)) {
+ if (Is<C>(*cur)) return Handle<C>::cast(cur);
}
- return NULL;
+ return Handle<C>::null();
}
@@ -157,8 +159,9 @@ MaybeObject* Accessors::ArrayGetLength(Isolate* isolate,
Object* object,
void*) {
// Traverse the prototype chain until we reach an array.
- JSArray* holder = FindInstanceOf<JSArray>(isolate, object);
- return holder == NULL ? Smi::FromInt(0) : holder->length();
+ Handle<JSArray> holder =
+ FindInstanceOf<JSArray>(isolate, handle(object, isolate));
+ return holder.is_null() ? Smi::FromInt(0) : holder->length();
}
@@ -561,23 +564,23 @@ Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate,
Object* object,
void*) {
- JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object);
- if (function_raw == NULL) return isolate->heap()->undefined_value();
- while (!function_raw->should_have_prototype()) {
- function_raw = FindInstanceOf<JSFunction>(isolate,
- function_raw->GetPrototype());
+ HandleScope scope(isolate);
+ Handle<JSFunction> function =
+ FindInstanceOf<JSFunction>(isolate, handle(object, isolate));
+ if (function.is_null()) return isolate->heap()->undefined_value();
+ while (!function->should_have_prototype()) {
+ function = FindInstanceOf<JSFunction>(
+ isolate,
+ Object::GetPrototype(isolate, function));
// There has to be one because we hit the getter.
- ASSERT(function_raw != NULL);
+ ASSERT(!function.is_null());
}
- if (!function_raw->has_prototype()) {
- HandleScope scope(isolate);
- Handle<JSFunction> function(function_raw);
+ if (!function->has_prototype()) {
Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function);
JSFunction::SetPrototype(function, proto);
- function_raw = *function;
}
- return function_raw->prototype();
+ return function->prototype();
}
@@ -585,13 +588,12 @@ MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate,
JSObject* object_raw,
Object* value_raw,
void*) {
- JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object_raw);
- if (function_raw == NULL) return isolate->heap()->undefined_value();
-
HandleScope scope(isolate);
- Handle<JSFunction> function(function_raw, isolate);
Handle<JSObject> object(object_raw, isolate);
Handle<Object> value(value_raw, isolate);
+ Handle<JSFunction> function = FindInstanceOf<JSFunction>(isolate, object);
+ if (function.is_null()) return isolate->heap()->undefined_value();
+
if (!function->should_have_prototype()) {
// Since we hit this accessor, object will have no prototype property.
Handle<Object> result;
@@ -638,18 +640,18 @@ const AccessorDescriptor Accessors::FunctionPrototype = {
MaybeObject* Accessors::FunctionGetLength(Isolate* isolate,
Object* object,
void*) {
- JSFunction* function = FindInstanceOf<JSFunction>(isolate, object);
- if (function == NULL) return Smi::FromInt(0);
+ HandleScope scope(isolate);
+ Handle<JSFunction> function =
+ FindInstanceOf<JSFunction>(isolate, handle(object, isolate));
+ if (function.is_null()) return Smi::FromInt(0);
// Check if already compiled.
if (function->shared()->is_compiled()) {
return Smi::FromInt(function->shared()->length());
}
// If the function isn't compiled yet, the length is not computed correctly
// yet. Compile it now and return the right length.
- HandleScope scope(isolate);
- Handle<JSFunction> function_handle(function);
- if (Compiler::EnsureCompiled(function_handle, KEEP_EXCEPTION)) {
- return Smi::FromInt(function_handle->shared()->length());
+ if (Compiler::EnsureCompiled(function, KEEP_EXCEPTION)) {
+ return Smi::FromInt(function->shared()->length());
}
return Failure::Exception();
}
@@ -670,8 +672,10 @@ const AccessorDescriptor Accessors::FunctionLength = {
MaybeObject* Accessors::FunctionGetName(Isolate* isolate,
Object* object,
void*) {
- JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
- return holder == NULL
+ HandleScope scope(isolate);
+ Handle<JSFunction> holder =
+ FindInstanceOf<JSFunction>(isolate, handle(object, isolate));
+ return holder.is_null()
? isolate->heap()->undefined_value()
: holder->shared()->name();
}
@@ -730,9 +734,9 @@ MaybeObject* Accessors::FunctionGetArguments(Isolate* isolate,
Object* object,
void*) {
HandleScope scope(isolate);
- JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
- if (holder == NULL) return isolate->heap()->undefined_value();
- Handle<JSFunction> function(holder, isolate);
+ Handle<JSFunction> function =
+ FindInstanceOf<JSFunction>(isolate, handle(object, isolate));
+ if (function.is_null()) return isolate->heap()->undefined_value();
if (function->shared()->native()) return isolate->heap()->null_value();
// Find the top invocation of the function by traversing frames.
@@ -855,10 +859,10 @@ MaybeObject* Accessors::FunctionGetCaller(Isolate* isolate,
void*) {
HandleScope scope(isolate);
DisallowHeapAllocation no_allocation;
- JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
- if (holder == NULL) return isolate->heap()->undefined_value();
- if (holder->shared()->native()) return isolate->heap()->null_value();
- Handle<JSFunction> function(holder, isolate);
+ Handle<JSFunction> function =
+ FindInstanceOf<JSFunction>(isolate, handle(object, isolate));
+ if (function.is_null()) return isolate->heap()->undefined_value();
+ if (function->shared()->native()) return isolate->heap()->null_value();
FrameFunctionIterator it(isolate, no_allocation);
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/builtins.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698