OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "test/cctest/test-api.h" | 7 #include "test/cctest/test-api.h" |
8 | 8 |
9 #include "include/v8-util.h" | 9 #include "include/v8-util.h" |
10 #include "src/api.h" | 10 #include "src/api.h" |
(...skipping 2518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2529 CHECK_EQ(42 * 5 + 40 * 5, | 2529 CHECK_EQ(42 * 5 + 40 * 5, |
2530 context->Global()->Get(v8_str("result"))->Int32Value()); | 2530 context->Global()->Get(v8_str("result"))->Int32Value()); |
2531 } | 2531 } |
2532 | 2532 |
2533 | 2533 |
2534 static int interceptor_call_count = 0; | 2534 static int interceptor_call_count = 0; |
2535 | 2535 |
2536 static void InterceptorICRefErrorGetter( | 2536 static void InterceptorICRefErrorGetter( |
2537 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { | 2537 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
2538 ApiTestFuzzer::Fuzz(); | 2538 ApiTestFuzzer::Fuzz(); |
2539 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { | 2539 if (!is_bootstrapping && v8_str("x")->Equals(name) && |
2540 interceptor_call_count++ < 20) { | |
2540 info.GetReturnValue().Set(call_ic_function2); | 2541 info.GetReturnValue().Set(call_ic_function2); |
2541 } | 2542 } |
2542 } | 2543 } |
2543 | 2544 |
2544 | 2545 |
2545 // This test should hit load and call ICs for the interceptor case. | 2546 // This test should hit load and call ICs for the interceptor case. |
2546 // Once in a while, the interceptor will reply that a property was not | 2547 // Once in a while, the interceptor will reply that a property was not |
2547 // found in which case we should get a reference error. | 2548 // found in which case we should get a reference error. |
2548 THREADED_TEST(InterceptorICReferenceErrors) { | 2549 THREADED_TEST(InterceptorICReferenceErrors) { |
2549 v8::Isolate* isolate = CcTest::isolate(); | 2550 v8::Isolate* isolate = CcTest::isolate(); |
2550 v8::HandleScope scope(isolate); | 2551 v8::HandleScope scope(isolate); |
2551 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 2552 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
2552 templ->SetHandler( | 2553 templ->SetHandler( |
2553 v8::NamedPropertyHandlerConfiguration(InterceptorICRefErrorGetter)); | 2554 v8::NamedPropertyHandlerConfiguration(InterceptorICRefErrorGetter)); |
2554 interceptor_call_count = -100000; // Generous limit for bootstrapping. | 2555 is_bootstrapping = true; |
2555 LocalContext context(0, templ, v8::Handle<Value>()); | 2556 LocalContext context(0, templ, v8::Handle<Value>()); |
2556 interceptor_call_count = 0; | 2557 is_bootstrapping = false; |
2557 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run(); | 2558 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run(); |
2558 v8::Handle<Value> value = CompileRun( | 2559 v8::Handle<Value> value = CompileRun( |
2559 "function f() {" | 2560 "function f() {" |
2560 " for (var i = 0; i < 1000; i++) {" | 2561 " for (var i = 0; i < 1000; i++) {" |
2561 " try { x; } catch(e) { return true; }" | 2562 " try { x; } catch(e) { return true; }" |
2562 " }" | 2563 " }" |
2563 " return false;" | 2564 " return false;" |
2564 "};" | 2565 "};" |
2565 "f();"); | 2566 "f();"); |
2566 CHECK_EQ(true, value->BooleanValue()); | 2567 CHECK_EQ(true, value->BooleanValue()); |
2567 interceptor_call_count = 0; | 2568 interceptor_call_count = 0; |
2568 value = CompileRun( | 2569 value = CompileRun( |
2569 "function g() {" | 2570 "function g() {" |
2570 " for (var i = 0; i < 1000; i++) {" | 2571 " for (var i = 0; i < 1000; i++) {" |
2571 " try { x(42); } catch(e) { return true; }" | 2572 " try { x(42); } catch(e) { return true; }" |
2572 " }" | 2573 " }" |
2573 " return false;" | 2574 " return false;" |
2574 "};" | 2575 "};" |
2575 "g();"); | 2576 "g();"); |
2576 CHECK_EQ(true, value->BooleanValue()); | 2577 CHECK_EQ(true, value->BooleanValue()); |
2577 } | 2578 } |
2578 | 2579 |
2579 | 2580 |
2580 static int interceptor_ic_exception_get_count = 0; | 2581 static int interceptor_ic_exception_get_count = 0; |
2581 | 2582 |
2582 static void InterceptorICExceptionGetter( | 2583 static void InterceptorICExceptionGetter( |
2583 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { | 2584 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
2584 ApiTestFuzzer::Fuzz(); | 2585 ApiTestFuzzer::Fuzz(); |
2586 if (is_bootstrapping) return; | |
2585 if (v8_str("x")->Equals(name) && ++interceptor_ic_exception_get_count < 20) { | 2587 if (v8_str("x")->Equals(name) && ++interceptor_ic_exception_get_count < 20) { |
2586 info.GetReturnValue().Set(call_ic_function3); | 2588 info.GetReturnValue().Set(call_ic_function3); |
2587 } | 2589 } |
2588 if (interceptor_ic_exception_get_count == 20) { | 2590 if (interceptor_ic_exception_get_count == 20) { |
2589 info.GetIsolate()->ThrowException(v8_num(42)); | 2591 info.GetIsolate()->ThrowException(v8_num(42)); |
2590 return; | 2592 return; |
2591 } | 2593 } |
2592 } | 2594 } |
2593 | 2595 |
2594 | 2596 |
2595 // Test interceptor load/call IC where the interceptor throws an | 2597 // Test interceptor load/call IC where the interceptor throws an |
2596 // exception once in a while. | 2598 // exception once in a while. |
2597 THREADED_TEST(InterceptorICGetterExceptions) { | 2599 THREADED_TEST(InterceptorICGetterExceptions) { |
2598 interceptor_ic_exception_get_count = 0; | 2600 interceptor_ic_exception_get_count = 0; |
2599 v8::Isolate* isolate = CcTest::isolate(); | 2601 v8::Isolate* isolate = CcTest::isolate(); |
2600 v8::HandleScope scope(isolate); | 2602 v8::HandleScope scope(isolate); |
2601 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 2603 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
2602 // Generous limit for bootstrapping. | 2604 // Generous limit for bootstrapping. |
Jakob Kummerow
2015/07/01 16:08:39
nit: outdated comment
| |
2603 interceptor_ic_exception_get_count = -100000; | |
2604 templ->SetHandler( | 2605 templ->SetHandler( |
2605 v8::NamedPropertyHandlerConfiguration(InterceptorICExceptionGetter)); | 2606 v8::NamedPropertyHandlerConfiguration(InterceptorICExceptionGetter)); |
2606 LocalContext context(0, templ, v8::Handle<Value>()); | 2607 LocalContext context(0, templ, v8::Handle<Value>()); |
2607 interceptor_ic_exception_get_count = 0; | |
2608 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run(); | 2608 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run(); |
2609 v8::Handle<Value> value = CompileRun( | 2609 v8::Handle<Value> value = CompileRun( |
2610 "function f() {" | 2610 "function f() {" |
2611 " for (var i = 0; i < 100; i++) {" | 2611 " for (var i = 0; i < 100; i++) {" |
2612 " try { x; } catch(e) { return true; }" | 2612 " try { x; } catch(e) { return true; }" |
2613 " }" | 2613 " }" |
2614 " return false;" | 2614 " return false;" |
2615 "};" | 2615 "};" |
2616 "f();"); | 2616 "f();"); |
2617 CHECK_EQ(true, value->BooleanValue()); | 2617 CHECK_EQ(true, value->BooleanValue()); |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3314 "var obj = intercepted_1;" | 3314 "var obj = intercepted_1;" |
3315 "obj.x = 4;" | 3315 "obj.x = 4;" |
3316 "eval('obj.x');" | 3316 "eval('obj.x');" |
3317 "eval('obj.x');" | 3317 "eval('obj.x');" |
3318 "eval('obj.x');" | 3318 "eval('obj.x');" |
3319 "obj = intercepted_2;" | 3319 "obj = intercepted_2;" |
3320 "obj.x = 9;" | 3320 "obj.x = 9;" |
3321 "eval('obj.x');", | 3321 "eval('obj.x');", |
3322 9); | 3322 9); |
3323 } | 3323 } |
OLD | NEW |