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

Unified Diff: src/accessors.cc

Issue 240323004: Handlify function.prototype accessor. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 | no next file » | no next file with comments »
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 2e3bfb80a4d9e2d5d4167506f753bcc954b2a5e8..866fac0d92a17757de07301f27e8920f18e1c981 100644
--- a/src/accessors.cc
+++ b/src/accessors.cc
@@ -773,74 +773,55 @@ Handle<AccessorInfo> Accessors::ScriptEvalFromFunctionNameInfo(
// Accessors::FunctionPrototype
//
+static Handle<Object> GetFunctionPrototype(Handle<Object> receiver,
+ Isolate* isolate) {
Yang 2014/04/17 05:55:42 I think the convention is (mostly) to have Isolate
+ Handle<JSFunction> function;
+ {
+ DisallowHeapAllocation no_allocation;
+ JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, *receiver);
+ if (function_raw == NULL) return isolate->factory()->undefined_value();
+ while (!function_raw->should_have_prototype()) {
+ function_raw = FindInstanceOf<JSFunction>(isolate,
+ function_raw->GetPrototype());
+ // There has to be one because we hit the getter.
+ ASSERT(function_raw != NULL);
+ }
+ function = Handle<JSFunction>(function_raw, isolate);
+ }
-Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) {
- CALL_HEAP_FUNCTION(function->GetIsolate(),
- Accessors::FunctionGetPrototype(function->GetIsolate(),
- *function,
- NULL),
- Object);
+ if (!function->has_prototype()) {
+ Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function);
+ JSFunction::SetPrototype(function, proto);
+ }
+ return Handle<Object>(function->prototype(), isolate);
}
-Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
- Handle<Object> prototype) {
- ASSERT(function->should_have_prototype());
- CALL_HEAP_FUNCTION(function->GetIsolate(),
- Accessors::FunctionSetPrototype(function->GetIsolate(),
- *function,
- *prototype,
- NULL),
- Object);
+Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) {
+ return GetFunctionPrototype(function, function->GetIsolate());
}
-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());
- // There has to be one because we hit the getter.
- ASSERT(function_raw != NULL);
- }
- if (!function_raw->has_prototype()) {
- HandleScope scope(isolate);
- Handle<JSFunction> function(function_raw);
- Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function);
- JSFunction::SetPrototype(function, proto);
- function_raw = *function;
+MaybeHandle<Object> SetFunctionPrototype(Handle<JSObject> receiver,
+ Handle<Object> value,
+ Isolate* isolate) {
Yang 2014/04/17 05:55:42 Same here.
+ Handle<JSFunction> function;
+ {
+ DisallowHeapAllocation no_allocation;
+ JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, *receiver);
+ if (function_raw == NULL) return isolate->factory()->undefined_value();
+ function = Handle<JSFunction>(function_raw, isolate);
}
- return function_raw->prototype();
-}
-
-
-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);
if (!function->should_have_prototype()) {
// Since we hit this accessor, object will have no prototype property.
- Handle<Object> result;
- ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
- isolate, result,
- JSObject::SetLocalPropertyIgnoreAttributes(
- object, isolate->factory()->prototype_string(), value, NONE));
- return *result;
+ return JSObject::SetLocalPropertyIgnoreAttributes(
+ receiver, isolate->factory()->prototype_string(), value, NONE);
}
Handle<Object> old_value;
- bool is_observed = *function == *object && function->map()->is_observed();
+ bool is_observed = *function == *receiver && function->map()->is_observed();
if (is_observed) {
if (function->has_prototype())
old_value = handle(function->prototype(), isolate);
@@ -856,7 +837,39 @@ MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate,
function, "update", isolate->factory()->prototype_string(), old_value);
}
- return *function;
+ return function;
+}
+
+
+Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
+ Handle<Object> prototype) {
+ ASSERT(function->should_have_prototype());
+ Isolate* isolate = function->GetIsolate();
+ Handle<Object> result;
+ SetFunctionPrototype(function, prototype, isolate).ToHandle(&result);
+ return result;
+}
+
+
+MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate,
+ Object* object,
+ void*) {
+ HandleScope scope(isolate);
+ return *GetFunctionPrototype(Handle<Object>(object, isolate), isolate);
+}
+
+
+MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate,
+ JSObject* object,
+ Object* value,
+ void*) {
+ Handle<Object> result;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, result,
+ SetFunctionPrototype(Handle<JSObject>(object, isolate),
+ Handle<Object>(value, isolate),
+ isolate));
+ return *result;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698