Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Unified Diff: test/cctest/test-api.cc

Issue 22903012: js accessor creation on Template (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: grokdump Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/mjsunit/fuzz-natives-part2.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index b1e82aae224c7d7b08864d7dd61e3acea72e181f..192f114ff623ba00d1f567330518745a6b8ff9fd 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -8257,11 +8257,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));
}
@@ -8269,7 +8277,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();
}
@@ -8287,6 +8302,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);
@@ -8302,12 +8323,27 @@ TEST(AccessControl) {
v8::Handle<Value>(),
v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
+
+ global_template->SetAccessorProperty(
+ v8_str("accessible_js_prop"),
+ v8::FunctionTemplate::New(EchoGetter),
+ v8::FunctionTemplate::New(EchoSetter),
+ v8::None,
+ 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->SetAccessorProperty(
+ v8_str("blocked_js_prop"),
+ v8::FunctionTemplate::New(UnreachableFunction),
+ v8::FunctionTemplate::New(UnreachableFunction),
+ v8::None,
+ v8::DEFAULT);
+
// Create an environment
v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
context0->Enter();
@@ -8500,26 +8536,47 @@ 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());
+ 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;})()");
@@ -8591,7 +8648,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.
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/mjsunit/fuzz-natives-part2.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698