Convert function.arguments to API-style accessor.
authorulan@chromium.org <ulan@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 28 Apr 2014 12:02:11 +0000 (12:02 +0000)
committerulan@chromium.org <ulan@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 28 Apr 2014 12:02:11 +0000 (12:02 +0000)
BUG=
R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/256693007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21014 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/accessors.cc
src/accessors.h
src/bootstrapper.cc

index eb99faa..f0f7791 100644 (file)
@@ -1096,26 +1096,47 @@ Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) {
 }
 
 
-Object* Accessors::FunctionGetArguments(Isolate* isolate,
-                                        Object* object,
-                                        void*) {
+void Accessors::FunctionArgumentsGetter(
+    v8::Local<v8::String> name,
+    const v8::PropertyCallbackInfo<v8::Value>& info) {
+  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
   HandleScope scope(isolate);
-  Handle<JSFunction> function;
+  Handle<Object> object = Utils::OpenHandle(*info.This());
+  MaybeHandle<JSFunction> maybe_function;
+
   {
     DisallowHeapAllocation no_allocation;
-    JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
-    if (holder == NULL) return isolate->heap()->undefined_value();
-    function = Handle<JSFunction>(holder, isolate);
+    JSFunction* function = FindInstanceOf<JSFunction>(isolate, *object);
+    if (function != NULL) maybe_function = Handle<JSFunction>(function);
+  }
+
+  Handle<JSFunction> function;
+  Handle<Object> result;
+  if (maybe_function.ToHandle(&function)) {
+    result = GetFunctionArguments(isolate, function);
+  } else {
+    result = isolate->factory()->undefined_value();
   }
-  return *GetFunctionArguments(isolate, function);
+  info.GetReturnValue().Set(Utils::ToLocal(result));
 }
 
 
-const AccessorDescriptor Accessors::FunctionArguments = {
-  FunctionGetArguments,
-  ReadOnlySetAccessor,
-  0
-};
+void Accessors::FunctionArgumentsSetter(
+    v8::Local<v8::String> name,
+    v8::Local<v8::Value> val,
+    const v8::PropertyCallbackInfo<void>& info) {
+  // Do nothing.
+}
+
+
+Handle<AccessorInfo> Accessors::FunctionArgumentsInfo(
+      Isolate* isolate, PropertyAttributes attributes) {
+  return MakeAccessor(isolate,
+                      isolate->factory()->arguments_string(),
+                      &FunctionArgumentsGetter,
+                      &FunctionArgumentsSetter,
+                      attributes);
+}
 
 
 //
index db63fda..2dcb860 100644 (file)
@@ -37,11 +37,11 @@ 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(FunctionArguments)              \
   V(FunctionCaller)                 \
   V(ArrayLength)
 
 #define ACCESSOR_INFO_LIST(V)       \
+  V(FunctionArguments)              \
   V(FunctionName)                   \
   V(FunctionLength)                 \
   V(FunctionPrototype)              \
@@ -114,21 +114,6 @@ class Accessors : public AllStatic {
                                       int* object_offset);
 
  private:
-  // Accessor functions only used through the descriptor.
-  static Object* FunctionSetPrototype(Isolate* isolate,
-                                      JSObject* object,
-                                      Object*,
-                                      void*);
-  static Object* FunctionGetPrototype(Isolate* isolate,
-                                      Object* object,
-                                      void*);
-  static Object* FunctionGetLength(Isolate* isolate,
-                                   Object* object,
-                                   void*);
-  static Object* FunctionGetName(Isolate* isolate, Object* object, void*);
-  static Object* FunctionGetArguments(Isolate* isolate,
-                                      Object* object,
-                                      void*);
   static Object* FunctionGetCaller(Isolate* isolate,
                                    Object* object,
                                    void*);
index d577772..775db59 100644 (file)
@@ -388,7 +388,6 @@ void Genesis::SetFunctionInstanceDescriptor(
   int size = (prototypeMode == DONT_ADD_PROTOTYPE) ? 4 : 5;
   Map::EnsureDescriptorSlack(map, size);
 
-  Handle<Foreign> args(factory()->NewForeign(&Accessors::FunctionArguments));
   Handle<Foreign> caller(factory()->NewForeign(&Accessors::FunctionCaller));
   PropertyAttributes attribs = static_cast<PropertyAttributes>(
       DONT_ENUM | DONT_DELETE | READ_ONLY);
@@ -407,8 +406,11 @@ void Genesis::SetFunctionInstanceDescriptor(
                           name, attribs);
     map->AppendDescriptor(&d);
   }
+  Handle<AccessorInfo> args =
+      Accessors::FunctionArgumentsInfo(isolate(), attribs);
   {  // Add arguments.
-    CallbacksDescriptor d(factory()->arguments_string(), args, attribs);
+    CallbacksDescriptor d(Handle<Name>(Name::cast(args->name())),
+                          args, attribs);
     map->AppendDescriptor(&d);
   }
   {  // Add caller.