Reviewers: Yang,

Message:
PTAL

Description:
Convert function.prototype to API-style accessor.

Please review this at https://codereview.chromium.org/246693005/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+44, -45 lines):
  M src/accessors.h
  M src/accessors.cc
  M src/bootstrapper.cc


Index: src/accessors.cc
diff --git a/src/accessors.cc b/src/accessors.cc
index 7a9d72515c328b4adf9ecbe2269d7b23b5c89cf2..3b8ea5b16e2c4d9c137059ef1d214b850b5925ae 100644
--- a/src/accessors.cc
+++ b/src/accessors.cc
@@ -797,12 +797,6 @@ static Handle<Object> GetFunctionPrototype(Isolate* isolate,
 }


-Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) {
-  return GetFunctionPrototype(function->GetIsolate(), function);
-}
-
-
-
 MaybeHandle<Object> SetFunctionPrototype(Isolate* isolate,
                                          Handle<JSObject> receiver,
                                          Handle<Object> value) {
@@ -841,6 +835,11 @@ MaybeHandle<Object> SetFunctionPrototype(Isolate* isolate,
 }


+Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) {
+  return GetFunctionPrototype(function->GetIsolate(), function);
+}
+
+
 Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
                                                Handle<Object> prototype) {
   ASSERT(function->should_have_prototype());
@@ -851,33 +850,43 @@ Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
 }


-MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate,
-                                             Object* object,
-                                             void*) {
+void Accessors::FunctionPrototypeGetter(
+    v8::Local<v8::String> name,
+    const v8::PropertyCallbackInfo<v8::Value>& info) {
+  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
   HandleScope scope(isolate);
-  return *GetFunctionPrototype(isolate, Handle<Object>(object, isolate));
+  Handle<Object> object = Utils::OpenHandle(*info.This());
+  Handle<Object> result = GetFunctionPrototype(isolate, object);
+  info.GetReturnValue().Set(Utils::ToLocal(result));
 }


-MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate,
-                                             JSObject* object,
-                                             Object* value,
-                                             void*) {
-  Handle<Object> result;
-  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
-      isolate, result,
-      SetFunctionPrototype(isolate,
-                           Handle<JSObject>(object, isolate),
-                           Handle<Object>(value, isolate)));
-  return *result;
+void Accessors::FunctionPrototypeSetter(
+    v8::Local<v8::String> name,
+    v8::Local<v8::Value> val,
+    const v8::PropertyCallbackInfo<void>& info) {
+  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
+  HandleScope scope(isolate);
+  Handle<JSObject> object = Utils::OpenHandle(*info.This());
+  Handle<Object> value = Utils::OpenHandle(*val);
+
+ MaybeHandle<Object> result = SetFunctionPrototype(isolate, object, value);
+  if (result.is_null()) {
+    if (isolate->has_pending_exception()) {
+      isolate->OptionalRescheduleException(false);
+    }
+  }
 }


-const AccessorDescriptor Accessors::FunctionPrototype = {
-  FunctionGetPrototype,
-  FunctionSetPrototype,
-  0
-};
+Handle<AccessorInfo> Accessors::FunctionPrototypeInfo(
+      Isolate* isolate, PropertyAttributes attributes) {
+  return MakeAccessor(isolate,
+                      isolate->factory()->prototype_string(),
+                      &FunctionPrototypeGetter,
+                      &FunctionPrototypeSetter,
+                      attributes);
+}


 //
Index: src/accessors.h
diff --git a/src/accessors.h b/src/accessors.h
index 196bce56998999606fb4c172036e583ea620949e..48d96c2d723b3eca976d1d467e8e9345da414ff6 100644
--- a/src/accessors.h
+++ b/src/accessors.h
@@ -37,7 +37,6 @@ namespace internal {
 // The list of accessor descriptors. This is a second-order macro
 // taking a macro to be applied to all accessor descriptor names.
 #define ACCESSOR_DESCRIPTOR_LIST(V) \
-  V(FunctionPrototype)              \
   V(FunctionLength)                 \
   V(FunctionName)                   \
   V(FunctionArguments)              \
@@ -45,6 +44,7 @@ namespace internal {
   V(ArrayLength)

 #define ACCESSOR_INFO_LIST(V)       \
+  V(FunctionPrototype)              \
   V(ScriptColumnOffset)             \
   V(ScriptCompilationType)          \
   V(ScriptContextData)              \
@@ -115,13 +115,6 @@ class Accessors : public AllStatic {

  private:
   // Accessor functions only used through the descriptor.
-  static MaybeObject* FunctionSetPrototype(Isolate* isolate,
-                                           JSObject* object,
-                                           Object*,
-                                           void*);
-  static MaybeObject* FunctionGetPrototype(Isolate* isolate,
-                                           Object* object,
-                                           void*);
   static MaybeObject* FunctionGetLength(Isolate* isolate,
                                         Object* object,
                                         void*);
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index 6c6e6b361150707da995ca6d9fe7e52f122d198b..5bfc3b708913b16eae915b6988b7f193862f7fe4 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -392,10 +392,6 @@ void Genesis::SetFunctionInstanceDescriptor(
   Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName));
Handle<Foreign> args(factory()->NewForeign(&Accessors::FunctionArguments)); Handle<Foreign> caller(factory()->NewForeign(&Accessors::FunctionCaller));
-  Handle<Foreign> prototype;
-  if (prototypeMode != DONT_ADD_PROTOTYPE) {
-    prototype = factory()->NewForeign(&Accessors::FunctionPrototype);
-  }
   PropertyAttributes attribs = static_cast<PropertyAttributes>(
       DONT_ENUM | DONT_DELETE | READ_ONLY);

@@ -416,11 +412,13 @@ void Genesis::SetFunctionInstanceDescriptor(
     map->AppendDescriptor(&d);
   }
   if (prototypeMode != DONT_ADD_PROTOTYPE) {
-    // Add prototype.
     if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) {
       attribs = static_cast<PropertyAttributes>(attribs & ~READ_ONLY);
     }
- CallbacksDescriptor d(factory()->prototype_string(), prototype, attribs);
+    Handle<AccessorInfo> prototype =
+        Accessors::FunctionPrototypeInfo(isolate(), attribs);
+    CallbacksDescriptor d(Handle<Name>(Name::cast(prototype->name())),
+                          prototype, attribs);
     map->AppendDescriptor(&d);
   }
 }
@@ -523,10 +521,6 @@ void Genesis::SetStrictFunctionInstanceDescriptor(
   Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName));
   Handle<AccessorPair> arguments(factory()->NewAccessorPair());
   Handle<AccessorPair> caller(factory()->NewAccessorPair());
-  Handle<Foreign> prototype;
-  if (prototypeMode != DONT_ADD_PROTOTYPE) {
-    prototype = factory()->NewForeign(&Accessors::FunctionPrototype);
-  }
   PropertyAttributes rw_attribs =
       static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
   PropertyAttributes ro_attribs =
@@ -553,7 +547,10 @@ void Genesis::SetStrictFunctionInstanceDescriptor(
     // Add prototype.
     PropertyAttributes attribs =
         prototypeMode == ADD_WRITEABLE_PROTOTYPE ? rw_attribs : ro_attribs;
- CallbacksDescriptor d(factory()->prototype_string(), prototype, attribs);
+    Handle<AccessorInfo> prototype =
+        Accessors::FunctionPrototypeInfo(isolate(), attribs);
+    CallbacksDescriptor d(Handle<Name>(Name::cast(prototype->name())),
+                          prototype, attribs);
     map->AppendDescriptor(&d);
   }
 }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to