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 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 "}" | 847 "}" |
848 "this.y = 42;" | 848 "this.y = 42;" |
849 "var result = 0;" | 849 "var result = 0;" |
850 "for (var i = 0; i < 10; i++) {" | 850 "for (var i = 0; i < 10; i++) {" |
851 " result += o.y;" | 851 " result += o.y;" |
852 "}" | 852 "}" |
853 "result"); | 853 "result"); |
854 CHECK_EQ(42 * 10, value->Int32Value(context.local()).FromJust()); | 854 CHECK_EQ(42 * 10, value->Int32Value(context.local()).FromJust()); |
855 } | 855 } |
856 | 856 |
857 // Test load of a non-existing global when a global object has an interceptor. | |
858 THREADED_TEST(InterceptorLoadGlobalICGlobalWithInterceptor) { | |
859 v8::Isolate* isolate = CcTest::isolate(); | |
860 v8::HandleScope scope(isolate); | |
861 v8::Local<v8::ObjectTemplate> templ_global = v8::ObjectTemplate::New(isolate); | |
862 templ_global->SetHandler(v8::NamedPropertyHandlerConfiguration( | |
863 EmptyInterceptorGetter, EmptyInterceptorSetter)); | |
864 | |
865 LocalContext context(nullptr, templ_global); | |
866 i::Handle<i::JSReceiver> global_proxy = | |
867 v8::Utils::OpenHandle<Object, i::JSReceiver>(context->Global()); | |
868 CHECK(global_proxy->IsJSGlobalProxy()); | |
869 i::Handle<i::JSGlobalObject> global( | |
870 i::JSGlobalObject::cast(global_proxy->map()->prototype())); | |
871 CHECK(global->map()->has_named_interceptor()); | |
872 | |
873 v8::Local<Value> value = CompileRun( | |
874 "var f = function() { " | |
875 " try {" | |
876 " x;" | |
877 " return false;" | |
878 " } catch(e) {" | |
879 " return true;" | |
880 " }" | |
881 "};" | |
882 "for (var i = 0; i < 10; i++) {" | |
883 " f();" | |
884 "};" | |
885 "f();"); | |
886 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust()); | |
887 | |
888 value = CompileRun( | |
889 "var f = function() { " | |
890 " try {" | |
891 " typeof(x);" | |
892 " return true;" | |
893 " } catch(e) {" | |
894 " return false;" | |
895 " }" | |
896 "};" | |
897 "for (var i = 0; i < 10; i++) {" | |
898 " f();" | |
899 "};" | |
900 "f();"); | |
901 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust()); | |
902 } | |
mvstanton
2016/06/23 16:09:28
Nice unit test +1.
| |
857 | 903 |
858 static void InterceptorLoadICGetter0( | 904 static void InterceptorLoadICGetter0( |
859 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { | 905 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
860 ApiTestFuzzer::Fuzz(); | 906 ApiTestFuzzer::Fuzz(); |
861 CHECK(v8_str("x") | 907 CHECK(v8_str("x") |
862 ->Equals(info.GetIsolate()->GetCurrentContext(), name) | 908 ->Equals(info.GetIsolate()->GetCurrentContext(), name) |
863 .FromJust()); | 909 .FromJust()); |
864 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 0)); | 910 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 0)); |
865 } | 911 } |
866 | 912 |
(...skipping 3040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3907 ->Set(env.local(), v8_str("Fun"), | 3953 ->Set(env.local(), v8_str("Fun"), |
3908 fun_templ->GetFunction(env.local()).ToLocalChecked()) | 3954 fun_templ->GetFunction(env.local()).ToLocalChecked()) |
3909 .FromJust()); | 3955 .FromJust()); |
3910 | 3956 |
3911 CompileRun( | 3957 CompileRun( |
3912 "var f = new Fun();" | 3958 "var f = new Fun();" |
3913 "Number.prototype.__proto__ = f;" | 3959 "Number.prototype.__proto__ = f;" |
3914 "var a = 42;" | 3960 "var a = 42;" |
3915 "for (var i = 0; i<3; i++) { a.foo; }"); | 3961 "for (var i = 0; i<3; i++) { a.foo; }"); |
3916 } | 3962 } |
OLD | NEW |