Index: test/cctest/test-api.cc |
=================================================================== |
--- test/cctest/test-api.cc (revision 2103) |
+++ test/cctest/test-api.cc (working copy) |
@@ -4827,6 +4827,23 @@ |
} |
+typedef v8::Handle<Value> (*NamedPropertyGetter)(Local<String> property, |
+ const AccessorInfo& info); |
+ |
+ |
+static void CheckInterceptorLoadIC(NamedPropertyGetter getter, |
+ const char* source, |
+ int expected) { |
+ v8::HandleScope scope; |
+ v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); |
+ templ->SetNamedPropertyHandler(getter); |
+ LocalContext context; |
+ context->Global()->Set(v8_str("o"), templ->NewInstance()); |
+ v8::Handle<Value> value = CompileRun(source); |
+ CHECK_EQ(expected, value->Int32Value()); |
+} |
+ |
+ |
static v8::Handle<Value> InterceptorLoadICGetter(Local<String> name, |
const AccessorInfo& info) { |
ApiTestFuzzer::Fuzz(); |
@@ -4837,17 +4854,12 @@ |
// This test should hit the load IC for the interceptor case. |
THREADED_TEST(InterceptorLoadIC) { |
- v8::HandleScope scope; |
- v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); |
- templ->SetNamedPropertyHandler(InterceptorLoadICGetter); |
- LocalContext context; |
- context->Global()->Set(v8_str("o"), templ->NewInstance()); |
- v8::Handle<Value> value = CompileRun( |
+ CheckInterceptorLoadIC(InterceptorLoadICGetter, |
"var result = 0;" |
"for (var i = 0; i < 1000; i++) {" |
" result = o.x;" |
- "}"); |
- CHECK_EQ(42, value->Int32Value()); |
+ "}", |
+ 42); |
} |
@@ -4863,19 +4875,8 @@ |
} |
-static void CheckInterceptorLoadIC(const char* source, int expected) { |
- v8::HandleScope scope; |
- v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); |
- templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); |
- LocalContext context; |
- context->Global()->Set(v8_str("o"), templ->NewInstance()); |
- v8::Handle<Value> value = CompileRun(source); |
- CHECK_EQ(expected, value->Int32Value()); |
-} |
- |
- |
THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { |
- CheckInterceptorLoadIC( |
+ CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
"var result = 0;" |
"o.y = 239;" |
"for (var i = 0; i < 1000; i++) {" |
@@ -4886,7 +4887,7 @@ |
THREADED_TEST(InterceptorLoadICWithSubstitutedProto) { |
- CheckInterceptorLoadIC( |
+ CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
"var result = 0;" |
"o.__proto__ = { 'y': 239 };" |
"for (var i = 0; i < 1000; i++) {" |
@@ -4897,7 +4898,7 @@ |
THREADED_TEST(InterceptorLoadICWithPropertyOnProto) { |
- CheckInterceptorLoadIC( |
+ CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
"var result = 0;" |
"o.__proto__.y = 239;" |
"for (var i = 0; i < 1000; i++) {" |
@@ -4908,7 +4909,7 @@ |
THREADED_TEST(InterceptorLoadICUndefined) { |
- CheckInterceptorLoadIC( |
+ CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
"var result = 0;" |
"for (var i = 0; i < 1000; i++) {" |
" result = (o.y == undefined) ? 239 : 42;" |
@@ -4918,7 +4919,7 @@ |
THREADED_TEST(InterceptorLoadICWithOverride) { |
- CheckInterceptorLoadIC( |
+ CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
"fst = new Object(); fst.__proto__ = o;" |
"snd = new Object(); snd.__proto__ = fst;" |
"var result1 = 0;" |
@@ -4935,6 +4936,21 @@ |
} |
+static v8::Handle<Value> InterceptorLoadICGetter0(Local<String> name, |
+ const AccessorInfo& info) { |
+ ApiTestFuzzer::Fuzz(); |
+ CHECK(v8_str("x")->Equals(name)); |
+ return v8::Integer::New(0); |
+} |
+ |
+ |
+THREADED_TEST(InterceptorReturningZero) { |
+ CheckInterceptorLoadIC(InterceptorLoadICGetter0, |
+ "o.x == undefined ? 1 : 0", |
+ 0); |
+} |
+ |
+ |
static v8::Handle<Value> InterceptorStoreICSetter( |
Local<String> key, Local<Value> value, const AccessorInfo&) { |
CHECK(v8_str("x")->Equals(key)); |