Reviewers: Sven Panne,

Message:
ptal

Description:
add setaccessorproperty to object

[email protected]

BUG=v8:2964

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

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

Affected files (+29, -21 lines):
  M include/v8.h
  M src/api.cc
  M test/cctest/test-api.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 7f1f8fba41d378c5e035b066154acae206747039..96caff4ab241dbb83c251214cf1ccaee058d88a0 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -2205,6 +2205,12 @@ class V8_EXPORT Object : public Value {
                            PropertyAttribute attribute = None,
                            AccessControl settings = DEFAULT);

+  void SetAccessorProperty(Local<String> name,
+                           Local<Function> getter,
+                           Local<Function> setter = Local<Function>(),
+                           PropertyAttribute attribute = None,
+                           AccessControl settings = DEFAULT);
+
   /**
    * Functionality for private properties.
    * This is an experimental feature, use at your own risk.
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 402598f40e3b9fc9ed5b8caad9855ea85f7d2d27..450ff74b1ade494313a2ad3d1259a14c8a895088 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -3488,6 +3488,27 @@ bool Object::SetDeclaredAccessor(Local<String> name,
 }


+void Object::SetAccessorProperty(Local<String> name,
+                                 Local<Function> getter,
+ Local<Function> setter = Local<Function>(),
+                                 AccessControl settings,
+                                 PropertyAttribute attributes) {
+  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+  ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false);
+  ENTER_V8(isolate);
+  i::HandleScope scope(isolate);
+  i::Handle<i::Object> getter_i = v8::Utils::OpenHandle(*getter);
+  i::Handle<i::Object> setter_i = v8::Utils::OpenHandle(*setter, true);
+  if (setter_i.is_null()) setter_i = isolate->factory()->null_value();
+  i::JSObject::DefineAccessor(v8::Utils::OpenHandle(*object),
+                              v8::Utils::OpenHandle(*name),
+                              getter_i,
+                              setter_i,
+                              static_cast<PropertyAttributes>(attribute),
+                              settings);
+}
+
+
 bool v8::Object::HasOwnProperty(Handle<String> key) {
   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
   ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()",
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index a1b05f901d0a52d67b14b04753ddf25c93d15806..a159522ff150b56c0c3ad2be783e55bc78376a22 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -21962,25 +21962,6 @@ class ApiCallOptimizationChecker {
     info.GetReturnValue().Set(v8_str("returned"));
   }

-  // TODO(dcarney): move this to v8.h
-  static void SetAccessorProperty(Local<Object> object,
-                                  Local<String> name,
-                                  Local<Function> getter,
- Local<Function> setter = Local<Function>()) {
-    i::Isolate* isolate = CcTest::i_isolate();
-    v8::AccessControl settings = v8::DEFAULT;
-    v8::PropertyAttribute attribute = v8::None;
-    i::Handle<i::Object> getter_i = v8::Utils::OpenHandle(*getter);
-    i::Handle<i::Object> setter_i = v8::Utils::OpenHandle(*setter, true);
-    if (setter_i.is_null()) setter_i = isolate->factory()->null_value();
-    i::JSObject::DefineAccessor(v8::Utils::OpenHandle(*object),
-                                v8::Utils::OpenHandle(*name),
-                                getter_i,
-                                setter_i,
-                                static_cast<PropertyAttributes>(attribute),
-                                settings);
-  }
-
   public:
     enum SignatureType {
       kNoSignature,
@@ -22049,9 +22030,9 @@ class ApiCallOptimizationChecker {
         global_holder = Local<Object>::Cast(global_holder->GetPrototype());
       }
       global_holder->Set(v8_str("g_f"), function);
- SetAccessorProperty(global_holder, v8_str("g_acc"), function, function); + global_holder->SetAccessorProperty(v8_str("g_acc"), function, function);
       function_holder->Set(v8_str("f"), function);
- SetAccessorProperty(function_holder, v8_str("acc"), function, function); + function_holder->SetAccessorProperty(v8_str("acc"), function, function);
       // Initialize expected values.
       callee = function;
       count = 0;


--
--
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