OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 7644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7655 Script::Compile(v8_str("this.propertyIsEnumerable(0)"))->Run(); | 7655 Script::Compile(v8_str("this.propertyIsEnumerable(0)"))->Run(); |
7656 CHECK(value->IsBoolean()); | 7656 CHECK(value->IsBoolean()); |
7657 CHECK(!value->BooleanValue()); | 7657 CHECK(!value->BooleanValue()); |
7658 | 7658 |
7659 value = Script::Compile(v8_str("x"))->Run(); | 7659 value = Script::Compile(v8_str("x"))->Run(); |
7660 CHECK_EQ(12, value->Int32Value()); | 7660 CHECK_EQ(12, value->Int32Value()); |
7661 | 7661 |
7662 value = Script::Compile(v8_str("f()"))->Run(); | 7662 value = Script::Compile(v8_str("f()"))->Run(); |
7663 CHECK_EQ(42, value->Int32Value()); | 7663 CHECK_EQ(42, value->Int32Value()); |
7664 | 7664 |
7665 Script::Compile(v8_str("y = 43"))->Run(); | 7665 Script::Compile(v8_str("y = 42"))->Run(); |
7666 CHECK_EQ(1, shadow_y_setter_call_count); | 7666 CHECK_EQ(1, shadow_y_setter_call_count); |
7667 value = Script::Compile(v8_str("y"))->Run(); | 7667 value = Script::Compile(v8_str("y"))->Run(); |
7668 CHECK_EQ(1, shadow_y_getter_call_count); | 7668 CHECK_EQ(1, shadow_y_getter_call_count); |
7669 CHECK_EQ(42, value->Int32Value()); | 7669 CHECK_EQ(42, value->Int32Value()); |
7670 } | 7670 } |
7671 | 7671 |
7672 | 7672 |
7673 THREADED_TEST(HiddenPrototype) { | 7673 THREADED_TEST(HiddenPrototype) { |
7674 v8::HandleScope handle_scope; | 7674 v8::HandleScope handle_scope; |
7675 LocalContext context; | 7675 LocalContext context; |
(...skipping 2577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10253 | 10253 |
10254 | 10254 |
10255 static v8::Handle<Value> ChildGetter(Local<String> name, | 10255 static v8::Handle<Value> ChildGetter(Local<String> name, |
10256 const AccessorInfo& info) { | 10256 const AccessorInfo& info) { |
10257 ApiTestFuzzer::Fuzz(); | 10257 ApiTestFuzzer::Fuzz(); |
10258 return v8_num(42); | 10258 return v8_num(42); |
10259 } | 10259 } |
10260 | 10260 |
10261 | 10261 |
10262 THREADED_TEST(Overriding) { | 10262 THREADED_TEST(Overriding) { |
10263 i::FLAG_es5_readonly = true; | |
10264 v8::HandleScope scope; | 10263 v8::HandleScope scope; |
10265 LocalContext context; | 10264 LocalContext context; |
10266 | 10265 |
10267 // Parent template. | 10266 // Parent template. |
10268 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New(); | 10267 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New(); |
10269 Local<ObjectTemplate> parent_instance_templ = | 10268 Local<ObjectTemplate> parent_instance_templ = |
10270 parent_templ->InstanceTemplate(); | 10269 parent_templ->InstanceTemplate(); |
10271 parent_instance_templ->SetAccessor(v8_str("f"), ParentGetter); | 10270 parent_instance_templ->SetAccessor(v8_str("f"), ParentGetter); |
10272 | 10271 |
10273 // Template that inherits from the parent template. | 10272 // Template that inherits from the parent template. |
(...skipping 26 matching lines...) Expand all Loading... |
10300 Local<v8::Object> instance = child_templ->GetFunction()->NewInstance(); | 10299 Local<v8::Object> instance = child_templ->GetFunction()->NewInstance(); |
10301 | 10300 |
10302 // Check that the child function overrides the parent one. | 10301 // Check that the child function overrides the parent one. |
10303 context->Global()->Set(v8_str("o"), instance); | 10302 context->Global()->Set(v8_str("o"), instance); |
10304 Local<Value> value = v8_compile("o.f")->Run(); | 10303 Local<Value> value = v8_compile("o.f")->Run(); |
10305 // Check that the 'g' that was added last is hit. | 10304 // Check that the 'g' that was added last is hit. |
10306 CHECK_EQ(42, value->Int32Value()); | 10305 CHECK_EQ(42, value->Int32Value()); |
10307 value = v8_compile("o.g")->Run(); | 10306 value = v8_compile("o.g")->Run(); |
10308 CHECK_EQ(42, value->Int32Value()); | 10307 CHECK_EQ(42, value->Int32Value()); |
10309 | 10308 |
10310 // Check that 'h' cannot be shadowed. | 10309 // Check 'h' can be shadowed. |
10311 value = v8_compile("o.h = 3; o.h")->Run(); | 10310 value = v8_compile("o.h = 3; o.h")->Run(); |
10312 CHECK_EQ(1, value->Int32Value()); | 10311 CHECK_EQ(3, value->Int32Value()); |
10313 | 10312 |
10314 // Check that 'i' cannot be shadowed or changed. | 10313 // Check 'i' is cannot be shadowed or changed. |
10315 value = v8_compile("o.i = 3; o.i")->Run(); | 10314 value = v8_compile("o.i = 3; o.i")->Run(); |
10316 CHECK_EQ(42, value->Int32Value()); | 10315 CHECK_EQ(42, value->Int32Value()); |
10317 } | 10316 } |
10318 | 10317 |
10319 | 10318 |
10320 static v8::Handle<Value> IsConstructHandler(const v8::Arguments& args) { | 10319 static v8::Handle<Value> IsConstructHandler(const v8::Arguments& args) { |
10321 ApiTestFuzzer::Fuzz(); | 10320 ApiTestFuzzer::Fuzz(); |
10322 return v8::Boolean::New(args.IsConstructCall()); | 10321 return v8::Boolean::New(args.IsConstructCall()); |
10323 } | 10322 } |
10324 | 10323 |
(...skipping 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12142 CHECK(!local_env.IsEmpty()); | 12141 CHECK(!local_env.IsEmpty()); |
12143 local_env->Enter(); | 12142 local_env->Enter(); |
12144 | 12143 |
12145 // Should complete without problems. | 12144 // Should complete without problems. |
12146 RegExpStringModificationTest().RunTest(); | 12145 RegExpStringModificationTest().RunTest(); |
12147 | 12146 |
12148 local_env->Exit(); | 12147 local_env->Exit(); |
12149 } | 12148 } |
12150 | 12149 |
12151 | 12150 |
12152 // Test that we cannot set a property on the global object if there | 12151 // Test that we can set a property on the global object even if there |
12153 // is a read-only property in the prototype chain. | 12152 // is a read-only property in the prototype chain. |
12154 TEST(ReadOnlyPropertyInGlobalProto) { | 12153 TEST(ReadOnlyPropertyInGlobalProto) { |
12155 i::FLAG_es5_readonly = true; | |
12156 v8::HandleScope scope; | 12154 v8::HandleScope scope; |
12157 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 12155 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); |
12158 LocalContext context(0, templ); | 12156 LocalContext context(0, templ); |
12159 v8::Handle<v8::Object> global = context->Global(); | 12157 v8::Handle<v8::Object> global = context->Global(); |
12160 v8::Handle<v8::Object> global_proto = | 12158 v8::Handle<v8::Object> global_proto = |
12161 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); | 12159 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); |
12162 global_proto->Set(v8_str("x"), v8::Integer::New(0), v8::ReadOnly); | 12160 global_proto->Set(v8_str("x"), v8::Integer::New(0), v8::ReadOnly); |
12163 global_proto->Set(v8_str("y"), v8::Integer::New(0), v8::ReadOnly); | 12161 global_proto->Set(v8_str("y"), v8::Integer::New(0), v8::ReadOnly); |
12164 // Check without 'eval' or 'with'. | 12162 // Check without 'eval' or 'with'. |
12165 v8::Handle<v8::Value> res = | 12163 v8::Handle<v8::Value> res = |
12166 CompileRun("function f() { x = 42; return x; }; f()"); | 12164 CompileRun("function f() { x = 42; return x; }; f()"); |
12167 CHECK_EQ(v8::Integer::New(0), res); | |
12168 // Check with 'eval'. | 12165 // Check with 'eval'. |
12169 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()"); | 12166 res = CompileRun("function f() { eval('1'); y = 42; return y; }; f()"); |
12170 CHECK_EQ(v8::Integer::New(0), res); | 12167 CHECK_EQ(v8::Integer::New(42), res); |
12171 // Check with 'with'. | 12168 // Check with 'with'. |
12172 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()"); | 12169 res = CompileRun("function f() { with (this) { y = 42 }; return y; }; f()"); |
12173 CHECK_EQ(v8::Integer::New(0), res); | 12170 CHECK_EQ(v8::Integer::New(42), res); |
12174 } | 12171 } |
12175 | 12172 |
12176 static int force_set_set_count = 0; | 12173 static int force_set_set_count = 0; |
12177 static int force_set_get_count = 0; | 12174 static int force_set_get_count = 0; |
12178 bool pass_on_get = false; | 12175 bool pass_on_get = false; |
12179 | 12176 |
12180 static v8::Handle<v8::Value> ForceSetGetter(v8::Local<v8::String> name, | 12177 static v8::Handle<v8::Value> ForceSetGetter(v8::Local<v8::String> name, |
12181 const v8::AccessorInfo& info) { | 12178 const v8::AccessorInfo& info) { |
12182 force_set_get_count++; | 12179 force_set_get_count++; |
12183 if (pass_on_get) { | 12180 if (pass_on_get) { |
(...skipping 4405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16589 v8::V8::SetFatalErrorHandler(CountingErrorCallback); | 16586 v8::V8::SetFatalErrorHandler(CountingErrorCallback); |
16590 v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8"); | 16587 v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8"); |
16591 i::Isolate::Current()->TearDown(); | 16588 i::Isolate::Current()->TearDown(); |
16592 CHECK(!i::Internals::IsInitialized(isolate)); | 16589 CHECK(!i::Internals::IsInitialized(isolate)); |
16593 CHECK_EQ(1, fatal_error_callback_counter); | 16590 CHECK_EQ(1, fatal_error_callback_counter); |
16594 CHECK(v8::String::Empty().IsEmpty()); | 16591 CHECK(v8::String::Empty().IsEmpty()); |
16595 CHECK_EQ(2, fatal_error_callback_counter); | 16592 CHECK_EQ(2, fatal_error_callback_counter); |
16596 CHECK(v8::String::Empty(isolate).IsEmpty()); | 16593 CHECK(v8::String::Empty(isolate).IsEmpty()); |
16597 CHECK_EQ(3, fatal_error_callback_counter); | 16594 CHECK_EQ(3, fatal_error_callback_counter); |
16598 } | 16595 } |
OLD | NEW |