Revision: 20926
Author:   [email protected]
Date:     Thu Apr 24 08:35:53 2014 UTC
Log:      Convert function.prototype to API-style accessor.

[email protected]

Review URL: https://codereview.chromium.org/246693005
http://code.google.com/p/v8/source/detail?r=20926

Modified:
 /branches/bleeding_edge/src/accessors.cc
 /branches/bleeding_edge/src/accessors.h
 /branches/bleeding_edge/src/bootstrapper.cc

=======================================
--- /branches/bleeding_edge/src/accessors.cc    Wed Apr 23 15:08:03 2014 UTC
+++ /branches/bleeding_edge/src/accessors.cc    Thu Apr 24 08:35:53 2014 UTC
@@ -797,16 +797,10 @@
 }


-Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) {
-  return GetFunctionPrototype(function->GetIsolate(), function);
-}
-
-
-
-MaybeHandle<Object> SetFunctionPrototype(Isolate* isolate,
-                                         Handle<JSObject> receiver,
-                                         Handle<Object> value) {
-    Handle<JSFunction> function;
+static Handle<Object> SetFunctionPrototype(Isolate* isolate,
+                                           Handle<JSObject> receiver,
+                                           Handle<Object> value) {
+  Handle<JSFunction> function;
   {
     DisallowHeapAllocation no_allocation;
JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, *receiver);
@@ -816,8 +810,10 @@

   if (!function->should_have_prototype()) {
     // Since we hit this accessor, object will have no prototype property.
-    return JSObject::SetLocalPropertyIgnoreAttributes(
-        receiver, isolate->factory()->prototype_string(), value, NONE);
+    MaybeHandle<Object> maybe_result =
+        JSObject::SetLocalPropertyIgnoreAttributes(
+            receiver, isolate->factory()->prototype_string(), value, NONE);
+    return maybe_result.ToHandleChecked();
   }

   Handle<Object> old_value;
@@ -839,45 +835,53 @@

   return function;
 }
+
+
+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());
   Isolate* isolate = function->GetIsolate();
-  Handle<Object> result;
-  SetFunctionPrototype(isolate, function, prototype).ToHandle(&result);
-  return result;
+  return SetFunctionPrototype(isolate, function, prototype);
 }


-Object* 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));
 }

+
+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);

-Object* 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;
+  SetFunctionPrototype(isolate, object, value);
 }


-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);
+}


 //
=======================================
--- /branches/bleeding_edge/src/accessors.h     Wed Apr 23 15:08:03 2014 UTC
+++ /branches/bleeding_edge/src/accessors.h     Thu Apr 24 08:35:53 2014 UTC
@@ -37,7 +37,6 @@
 // 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 @@
   V(ArrayLength)

 #define ACCESSOR_INFO_LIST(V)       \
+  V(FunctionPrototype)              \
   V(ScriptColumnOffset)             \
   V(ScriptCompilationType)          \
   V(ScriptContextData)              \
=======================================
--- /branches/bleeding_edge/src/bootstrapper.cc Tue Apr 22 12:24:28 2014 UTC
+++ /branches/bleeding_edge/src/bootstrapper.cc Thu Apr 24 08:35:53 2014 UTC
@@ -392,10 +392,6 @@
   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 @@
     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 @@
   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 @@
     // 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