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

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

Issue 12494012: new style of property/function callbacks (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 7 years, 8 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
« src/x64/macro-assembler-x64.h ('K') | « src/x64/stub-cache-x64.cc ('k') | no next file » | 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 9d05c0f795a55dc23fb0fe2ad780d90db863adc3..8213c36bf50bbc5f5d7c379ec75665acbe3ea2f4 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -803,31 +803,84 @@ THREADED_TEST(GlobalProperties) {
static v8::Handle<Value> handle_call(const v8::Arguments& args) {
ApiTestFuzzer::Fuzz();
+ args.GetReturnValue().Set(v8_str("bad value"));
return v8_num(102);
}
+static v8::Handle<Value> handle_call_indirect(const v8::Arguments& args) {
+ ApiTestFuzzer::Fuzz();
+ args.GetReturnValue().Set(v8_str("bad value"));
+ args.GetReturnValue().Set(v8_num(102));
+ return v8::Handle<Value>();
+}
+
+static void handle_callback(const v8::FunctionCallbackInfo<Value>& info) {
+ ApiTestFuzzer::Fuzz();
+ info.GetReturnValue().Set(v8_str("bad value"));
+ info.GetReturnValue().Set(v8_num(102));
+}
+
static v8::Handle<Value> construct_call(const v8::Arguments& args) {
ApiTestFuzzer::Fuzz();
args.This()->Set(v8_str("x"), v8_num(1));
args.This()->Set(v8_str("y"), v8_num(2));
+ args.GetReturnValue().Set(v8_str("bad value"));
return args.This();
}
-static v8::Handle<Value> Return239(Local<String> name, const AccessorInfo&) {
+static v8::Handle<Value> construct_call_indirect(const v8::Arguments& args) {
ApiTestFuzzer::Fuzz();
+ args.This()->Set(v8_str("x"), v8_num(1));
+ args.This()->Set(v8_str("y"), v8_num(2));
+ args.GetReturnValue().Set(v8_str("bad value"));
+ args.GetReturnValue().Set(args.This());
+ return v8::Handle<Value>();
+}
+
+static void construct_callback(
+ const v8::FunctionCallbackInfo<Value>& info) {
+ ApiTestFuzzer::Fuzz();
+ info.This()->Set(v8_str("x"), v8_num(1));
+ info.This()->Set(v8_str("y"), v8_num(2));
+ info.GetReturnValue().Set(v8_str("bad value"));
+ info.GetReturnValue().Set(info.This());
+}
+
+
+static v8::Handle<Value> Return239(
+ Local<String> name, const AccessorInfo& info) {
+ ApiTestFuzzer::Fuzz();
+ info.GetReturnValue().Set(v8_str("bad value"));
return v8_num(239);
}
+static v8::Handle<Value> Return239Indirect(
+ Local<String> name, const AccessorInfo& info) {
+ ApiTestFuzzer::Fuzz();
+ Handle<Value> value = v8_num(239);
+ info.GetReturnValue().Set(v8_str("bad value"));
+ info.GetReturnValue().Set(value);
+ return v8::Handle<Value>();
+}
-THREADED_TEST(FunctionTemplate) {
- LocalContext env;
- v8::HandleScope scope(env->GetIsolate());
+static void Return239Callback(
+ Local<String> name, const v8::PropertyCallbackInfo<Value>& info) {
+ ApiTestFuzzer::Fuzz();
+ info.GetReturnValue().Set(v8_str("bad value"));
+ info.GetReturnValue().Set(v8_num(239));
+}
+
+
+template<typename Handler>
+static void TestFunctionTemplateInitializer(LocalContext* env,
+ Handler handler) {
+ // Test constructor calls.
{
Local<v8::FunctionTemplate> fun_templ =
- v8::FunctionTemplate::New(handle_call);
+ v8::FunctionTemplate::New(handler);
Local<Function> fun = fun_templ->GetFunction();
- env->Global()->Set(v8_str("obj"), fun);
+ (*env)->Global()->Set(v8_str("obj"), fun);
Local<Script> script = v8_compile("obj()");
CHECK_EQ(102, script->Run()->Int32Value());
}
@@ -835,29 +888,47 @@ THREADED_TEST(FunctionTemplate) {
// previous one.
{
Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
- fun_templ->SetCallHandler(handle_call);
+ fun_templ->SetCallHandler(handler);
Local<Function> fun = fun_templ->GetFunction();
- env->Global()->Set(v8_str("obj"), fun);
+ (*env)->Global()->Set(v8_str("obj"), fun);
Local<Script> script = v8_compile("obj()");
CHECK_EQ(102, script->Run()->Int32Value());
}
- // Test constructor calls.
- {
- Local<v8::FunctionTemplate> fun_templ =
- v8::FunctionTemplate::New(construct_call);
- fun_templ->SetClassName(v8_str("funky"));
- fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), Return239);
- Local<Function> fun = fun_templ->GetFunction();
- env->Global()->Set(v8_str("obj"), fun);
- Local<Script> script = v8_compile("var s = new obj(); s.x");
- CHECK_EQ(1, script->Run()->Int32Value());
+}
- Local<Value> result = v8_compile("(new obj()).toString()")->Run();
- CHECK_EQ(v8_str("[object funky]"), result);
- result = v8_compile("(new obj()).m")->Run();
- CHECK_EQ(239, result->Int32Value());
- }
+template<typename Constructor, typename Accessor>
+static void TestFunctionTemplateAccessor(LocalContext* env,
+ Constructor constructor,
+ Accessor accessor) {
+ Local<v8::FunctionTemplate> fun_templ =
+ v8::FunctionTemplate::New(construct_call);
+ fun_templ->SetClassName(v8_str("funky"));
+ fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor);
+ Local<Function> fun = fun_templ->GetFunction();
+ (*env)->Global()->Set(v8_str("obj"), fun);
+ Local<Script> script = v8_compile("var s = new obj(); s.x");
+ CHECK_EQ(1, script->Run()->Int32Value());
+ Local<Value> result = v8_compile("(new obj()).toString()")->Run();
+ CHECK_EQ(v8_str("[object funky]"), result);
+ result = v8_compile("(new obj()).m")->Run();
+ CHECK_EQ(239, result->Int32Value());
+}
+
+
+THREADED_TEST(FunctionTemplate) {
+ LocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+
+ TestFunctionTemplateInitializer(&env, handle_call);
+ TestFunctionTemplateInitializer(&env, handle_call_indirect);
+ TestFunctionTemplateInitializer(&env, handle_callback);
+
+ TestFunctionTemplateAccessor(&env, construct_call, Return239);
+ TestFunctionTemplateAccessor(&env,
+ construct_call_indirect,
+ Return239Indirect);
+ TestFunctionTemplateAccessor(&env, construct_callback, Return239Callback);
}
@@ -4205,7 +4276,10 @@ THREADED_TEST(SetterOnly) {
THREADED_TEST(NoAccessors) {
v8::HandleScope scope(v8::Isolate::GetCurrent());
Local<ObjectTemplate> templ = ObjectTemplate::New();
- templ->SetAccessor(v8_str("x"), NULL, NULL, v8_str("donut"));
+ templ->SetAccessor(v8_str("x"),
+ static_cast<v8::AccessorGetter>(NULL),
+ NULL,
+ v8_str("donut"));
LocalContext context;
context->Global()->Set(v8_str("obj"), templ->NewInstance());
Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x"));
@@ -4866,8 +4940,7 @@ THREADED_TEST(UndetectableObject) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- Local<v8::FunctionTemplate> desc =
- v8::FunctionTemplate::New(0, v8::Handle<Value>());
+ Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New();
desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
Local<v8::Object> obj = desc->GetFunction()->NewInstance();
@@ -4910,8 +4983,7 @@ THREADED_TEST(VoidLiteral) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- Local<v8::FunctionTemplate> desc =
- v8::FunctionTemplate::New(0, v8::Handle<Value>());
+ Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New();
desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
Local<v8::Object> obj = desc->GetFunction()->NewInstance();
@@ -4954,8 +5026,7 @@ THREADED_TEST(ExtensibleOnUndetectable) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- Local<v8::FunctionTemplate> desc =
- v8::FunctionTemplate::New(0, v8::Handle<Value>());
+ Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New();
desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
Local<v8::Object> obj = desc->GetFunction()->NewInstance();
@@ -10061,29 +10132,56 @@ THREADED_TEST(CallICFastApi_DirectCall_Throw) {
}
-v8::Handle<v8::Value> DirectGetterCallback(Local<String> name,
- const v8::AccessorInfo& info) {
+static Handle<Value> DoDirectGetter() {
if (++p_getter_count % 3 == 0) {
HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
GenerateSomeGarbage();
}
+ return v8_str("Direct Getter Result");
+}
+
+static v8::Handle<v8::Value> DirectGetter(Local<String> name,
+ const v8::AccessorInfo& info) {
+ info.GetReturnValue().Set(v8_str("Garbage"));
+ return DoDirectGetter();
+}
+
+static v8::Handle<v8::Value> DirectGetterIndirect(
+ Local<String> name,
+ const v8::AccessorInfo& info) {
+ info.GetReturnValue().Set(DoDirectGetter());
return v8::Handle<v8::Value>();
}
+static void DirectGetterCallback(
+ Local<String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ info.GetReturnValue().Set(DoDirectGetter());
+}
-THREADED_TEST(LoadICFastApi_DirectCall_GCMoveStub) {
+
+template<typename Accessor>
+static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) {
LocalContext context;
v8::HandleScope scope(context->GetIsolate());
v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New();
- obj->SetAccessor(v8_str("p1"), DirectGetterCallback);
+ obj->SetAccessor(v8_str("p1"), accessor);
context->Global()->Set(v8_str("o1"), obj->NewInstance());
p_getter_count = 0;
- CompileRun(
+ v8::Handle<v8::Value> result = CompileRun(
"function f() {"
" for (var i = 0; i < 30; i++) o1.p1;"
+ " return o1.p1"
"}"
"f();");
- CHECK_EQ(30, p_getter_count);
+ CHECK_EQ(v8_str("Direct Getter Result"), result);
+ CHECK_EQ(31, p_getter_count);
+}
+
+THREADED_TEST(LoadICFastApi_DirectCall_GCMoveStub) {
+ LoadICFastApi_DirectCall_GCMoveStub(DirectGetter);
+ LoadICFastApi_DirectCall_GCMoveStub(DirectGetterIndirect);
+ LoadICFastApi_DirectCall_GCMoveStub(DirectGetterCallback);
}
@@ -10762,7 +10860,7 @@ THREADED_TEST(InterceptorICSetterExceptions) {
THREADED_TEST(NullNamedInterceptor) {
v8::HandleScope scope(v8::Isolate::GetCurrent());
v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
- templ->SetNamedPropertyHandler(0);
+ templ->SetNamedPropertyHandler(static_cast<v8::NamedPropertyGetter>(0));
LocalContext context;
templ->Set("x", v8_num(42));
v8::Handle<v8::Object> obj = templ->NewInstance();
@@ -10777,7 +10875,7 @@ THREADED_TEST(NullNamedInterceptor) {
THREADED_TEST(NullIndexedInterceptor) {
v8::HandleScope scope(v8::Isolate::GetCurrent());
v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
- templ->SetIndexedPropertyHandler(0);
+ templ->SetIndexedPropertyHandler(static_cast<v8::IndexedPropertyGetter>(0));
LocalContext context;
templ->Set("42", v8_num(42));
v8::Handle<v8::Object> obj = templ->NewInstance();
« src/x64/macro-assembler-x64.h ('K') | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698