Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 3be500814533e45ee0b6273f45577438fa35019f..17a5401b16d0c4c0e289cea4d24b4abb21fffbc5 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -8228,11 +8228,19 @@ static bool IndexedAccessBlocker(Local<v8::Object> global, |
} |
-static int g_echo_value = -1; |
+static int g_echo_value_1 = -1; |
+static int g_echo_value_2 = -1; |
+ |
+ |
static void EchoGetter( |
Local<String> name, |
const v8::PropertyCallbackInfo<v8::Value>& info) { |
- info.GetReturnValue().Set(v8_num(g_echo_value)); |
+ info.GetReturnValue().Set(v8_num(g_echo_value_1)); |
+} |
+ |
+ |
+static void EchoGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
+ info.GetReturnValue().Set(v8_num(g_echo_value_2)); |
} |
@@ -8240,7 +8248,14 @@ static void EchoSetter(Local<String> name, |
Local<Value> value, |
const v8::PropertyCallbackInfo<void>&) { |
if (value->IsNumber()) |
- g_echo_value = value->Int32Value(); |
+ g_echo_value_1 = value->Int32Value(); |
+} |
+ |
+ |
+static void EchoSetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
+ v8::Handle<v8::Value> value = info[0]; |
+ if (value->IsNumber()) |
+ g_echo_value_2 = value->Int32Value(); |
} |
@@ -8258,6 +8273,12 @@ static void UnreachableSetter(Local<String>, |
} |
+static void UnreachableFunction( |
+ const v8::FunctionCallbackInfo<v8::Value>& info) { |
+ CHECK(false); // This function should not be called.. |
+} |
+ |
+ |
TEST(AccessControl) { |
v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
v8::HandleScope handle_scope(isolate); |
@@ -8273,12 +8294,26 @@ TEST(AccessControl) { |
v8::Handle<Value>(), |
v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); |
+ global_template->SetJsAccessor( |
+ isolate, |
+ v8_str("accessible_js_prop"), |
+ v8::FunctionTemplate::New(EchoGetter), |
+ v8::FunctionTemplate::New(EchoSetter), |
+ v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); |
+ |
// Add an accessor that is not accessible by cross-domain JS code. |
global_template->SetAccessor(v8_str("blocked_prop"), |
UnreachableGetter, UnreachableSetter, |
v8::Handle<Value>(), |
v8::DEFAULT); |
+ global_template->SetJsAccessor( |
+ isolate, |
+ v8_str("blocked_js_prop"), |
+ v8::FunctionTemplate::New(UnreachableFunction), |
+ v8::FunctionTemplate::New(UnreachableFunction), |
+ v8::DEFAULT); |
+ |
// Create an environment |
v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); |
context0->Enter(); |
@@ -8471,26 +8506,48 @@ TEST(AccessControl) { |
value = CompileRun("other.accessible_prop = 3"); |
CHECK(value->IsNumber()); |
CHECK_EQ(3, value->Int32Value()); |
- CHECK_EQ(3, g_echo_value); |
+ CHECK_EQ(3, g_echo_value_1); |
+ |
+ // Access accessible js property |
+ value = CompileRun("other.accessible_js_prop = 3"); |
+ CHECK(value->IsNumber()); |
+ CHECK_EQ(3, value->Int32Value()); |
+ CHECK_EQ(3, g_echo_value_2); |
value = CompileRun("other.accessible_prop"); |
CHECK(value->IsNumber()); |
CHECK_EQ(3, value->Int32Value()); |
+ value = CompileRun("other.accessible_js_prop"); |
+ CHECK(value->IsNumber()); |
+ CHECK_EQ(3, value->Int32Value()); |
+ |
value = CompileRun( |
"Object.getOwnPropertyDescriptor(other, 'accessible_prop').value"); |
CHECK(value->IsNumber()); |
CHECK_EQ(3, value->Int32Value()); |
+ // TODO(dcarney): not sure why this isn't working |
+ value = CompileRun( |
+ "Object.getOwnPropertyDescriptor(other, 'accessible_js_prop').get()"); |
+ CHECK(value->IsNumber()); |
+ CHECK_EQ(3, value->Int32Value()); |
+ |
value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')"); |
CHECK(value->IsTrue()); |
+ value = CompileRun("propertyIsEnumerable.call(other, 'accessible_js_prop')"); |
+ CHECK(value->IsTrue()); |
+ |
// Enumeration doesn't enumerate accessors from inaccessible objects in |
// the prototype chain even if the accessors are in themselves accessible. |
value = |
CompileRun("(function(){var obj = {'__proto__':other};" |
"for (var p in obj)" |
- " if (p == 'accessible_prop' || p == 'blocked_prop') {" |
+ " if (p == 'accessible_prop' ||" |
+ " p == 'accessible_js_prop' ||" |
+ " p == 'blocked_js_prop' ||" |
+ " p == 'blocked_js_prop') {" |
" return false;" |
" }" |
"return true;})()"); |
@@ -8562,7 +8619,7 @@ TEST(AccessControlES5) { |
// Make sure that we can set the accessible accessors value using normal |
// assignment. |
CompileRun("other.accessible_prop = 42"); |
- CHECK_EQ(42, g_echo_value); |
+ CHECK_EQ(42, g_echo_value_1); |
v8::Handle<Value> value; |
// We follow Safari in ignoring assignments to host object accessors. |