OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 3021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3032 result = script_define->Run(); | 3032 result = script_define->Run(); |
3033 CHECK_EQ(result, v8_num(43)); | 3033 CHECK_EQ(result, v8_num(43)); |
3034 result = script_desc->Run(); | 3034 result = script_desc->Run(); |
3035 CHECK_EQ(result->BooleanValue(), false); | 3035 CHECK_EQ(result->BooleanValue(), false); |
3036 | 3036 |
3037 // Make sure that it is not possible to redefine again | 3037 // Make sure that it is not possible to redefine again |
3038 v8::TryCatch try_catch; | 3038 v8::TryCatch try_catch; |
3039 result = script_define->Run(); | 3039 result = script_define->Run(); |
3040 CHECK(try_catch.HasCaught()); | 3040 CHECK(try_catch.HasCaught()); |
3041 String::AsciiValue exception_value(try_catch.Exception()); | 3041 String::AsciiValue exception_value(try_catch.Exception()); |
3042 CHECK_EQ(*exception_value, | 3042 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x"); |
3043 "TypeError: Cannot redefine property: defineProperty"); | |
3044 } | 3043 } |
3045 | 3044 |
3046 THREADED_TEST(DefinePropertyOnDefineGetterSetter) { | 3045 THREADED_TEST(DefinePropertyOnDefineGetterSetter) { |
3047 v8::HandleScope scope; | 3046 v8::HandleScope scope; |
3048 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 3047 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
3049 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); | 3048 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); |
3050 LocalContext context; | 3049 LocalContext context; |
3051 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 3050 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
3052 | 3051 |
3053 Local<Script> script_desc = Script::Compile(v8_str("var prop =" | 3052 Local<Script> script_desc = Script::Compile(v8_str("var prop =" |
(...skipping 24 matching lines...) Expand all Loading... |
3078 result = script_define->Run(); | 3077 result = script_define->Run(); |
3079 CHECK_EQ(result, v8_num(43)); | 3078 CHECK_EQ(result, v8_num(43)); |
3080 result = script_desc->Run(); | 3079 result = script_desc->Run(); |
3081 | 3080 |
3082 CHECK_EQ(result->BooleanValue(), false); | 3081 CHECK_EQ(result->BooleanValue(), false); |
3083 | 3082 |
3084 v8::TryCatch try_catch; | 3083 v8::TryCatch try_catch; |
3085 result = script_define->Run(); | 3084 result = script_define->Run(); |
3086 CHECK(try_catch.HasCaught()); | 3085 CHECK(try_catch.HasCaught()); |
3087 String::AsciiValue exception_value(try_catch.Exception()); | 3086 String::AsciiValue exception_value(try_catch.Exception()); |
3088 CHECK_EQ(*exception_value, | 3087 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x"); |
3089 "TypeError: Cannot redefine property: defineProperty"); | |
3090 } | 3088 } |
3091 | 3089 |
3092 | 3090 |
3093 static v8::Handle<v8::Object> GetGlobalProperty(LocalContext* context, | 3091 static v8::Handle<v8::Object> GetGlobalProperty(LocalContext* context, |
3094 char const* name) { | 3092 char const* name) { |
3095 return v8::Handle<v8::Object>::Cast((*context)->Global()->Get(v8_str(name))); | 3093 return v8::Handle<v8::Object>::Cast((*context)->Global()->Get(v8_str(name))); |
3096 } | 3094 } |
3097 | 3095 |
3098 | 3096 |
3099 THREADED_TEST(DefineAPIAccessorOnObject) { | 3097 THREADED_TEST(DefineAPIAccessorOnObject) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3197 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); | 3195 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); |
3198 CHECK(!GetGlobalProperty(&context, "obj2")-> | 3196 CHECK(!GetGlobalProperty(&context, "obj2")-> |
3199 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); | 3197 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); |
3200 | 3198 |
3201 { | 3199 { |
3202 v8::TryCatch try_catch; | 3200 v8::TryCatch try_catch; |
3203 CompileRun("Object.defineProperty(obj1, 'x'," | 3201 CompileRun("Object.defineProperty(obj1, 'x'," |
3204 "{get: function() { return 'func'; }})"); | 3202 "{get: function() { return 'func'; }})"); |
3205 CHECK(try_catch.HasCaught()); | 3203 CHECK(try_catch.HasCaught()); |
3206 String::AsciiValue exception_value(try_catch.Exception()); | 3204 String::AsciiValue exception_value(try_catch.Exception()); |
3207 CHECK_EQ(*exception_value, | 3205 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x"); |
3208 "TypeError: Cannot redefine property: defineProperty"); | |
3209 } | 3206 } |
3210 { | 3207 { |
3211 v8::TryCatch try_catch; | 3208 v8::TryCatch try_catch; |
3212 CompileRun("Object.defineProperty(obj2, 'x'," | 3209 CompileRun("Object.defineProperty(obj2, 'x'," |
3213 "{get: function() { return 'func'; }})"); | 3210 "{get: function() { return 'func'; }})"); |
3214 CHECK(try_catch.HasCaught()); | 3211 CHECK(try_catch.HasCaught()); |
3215 String::AsciiValue exception_value(try_catch.Exception()); | 3212 String::AsciiValue exception_value(try_catch.Exception()); |
3216 CHECK_EQ(*exception_value, | 3213 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x"); |
3217 "TypeError: Cannot redefine property: defineProperty"); | |
3218 } | 3214 } |
3219 } | 3215 } |
3220 | 3216 |
3221 | 3217 |
3222 static v8::Handle<Value> Get239Value(Local<String> name, | 3218 static v8::Handle<Value> Get239Value(Local<String> name, |
3223 const AccessorInfo& info) { | 3219 const AccessorInfo& info) { |
3224 ApiTestFuzzer::Fuzz(); | 3220 ApiTestFuzzer::Fuzz(); |
3225 CHECK_EQ(info.Data(), v8_str("donut")); | 3221 CHECK_EQ(info.Data(), v8_str("donut")); |
3226 CHECK_EQ(name, v8_str("239")); | 3222 CHECK_EQ(name, v8_str("239")); |
3227 return name; | 3223 return name; |
(...skipping 6340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9568 return count; | 9564 return count; |
9569 } | 9565 } |
9570 | 9566 |
9571 | 9567 |
9572 static void CheckSurvivingGlobalObjectsCount(int expected) { | 9568 static void CheckSurvivingGlobalObjectsCount(int expected) { |
9573 // We need to collect all garbage twice to be sure that everything | 9569 // We need to collect all garbage twice to be sure that everything |
9574 // has been collected. This is because inline caches are cleared in | 9570 // has been collected. This is because inline caches are cleared in |
9575 // the first garbage collection but some of the maps have already | 9571 // the first garbage collection but some of the maps have already |
9576 // been marked at that point. Therefore some of the maps are not | 9572 // been marked at that point. Therefore some of the maps are not |
9577 // collected until the second garbage collection. | 9573 // collected until the second garbage collection. |
9578 HEAP->global_context_map(); | |
9579 HEAP->CollectAllGarbage(false); | 9574 HEAP->CollectAllGarbage(false); |
9580 HEAP->CollectAllGarbage(false); | 9575 HEAP->CollectAllGarbage(false); |
9581 int count = GetGlobalObjectsCount(); | 9576 int count = GetGlobalObjectsCount(); |
9582 #ifdef DEBUG | 9577 #ifdef DEBUG |
9583 if (count != expected) HEAP->TracePathToGlobal(); | 9578 if (count != expected) HEAP->TracePathToGlobal(); |
9584 #endif | 9579 #endif |
9585 CHECK_EQ(expected, count); | 9580 CHECK_EQ(expected, count); |
9586 } | 9581 } |
9587 | 9582 |
9588 | 9583 |
(...skipping 4889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14478 | 14473 |
14479 THREADED_TEST(CallAPIFunctionOnNonObject) { | 14474 THREADED_TEST(CallAPIFunctionOnNonObject) { |
14480 v8::HandleScope scope; | 14475 v8::HandleScope scope; |
14481 LocalContext context; | 14476 LocalContext context; |
14482 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); | 14477 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); |
14483 Handle<Function> function = templ->GetFunction(); | 14478 Handle<Function> function = templ->GetFunction(); |
14484 context->Global()->Set(v8_str("f"), function); | 14479 context->Global()->Set(v8_str("f"), function); |
14485 TryCatch try_catch; | 14480 TryCatch try_catch; |
14486 CompileRun("f.call(2)"); | 14481 CompileRun("f.call(2)"); |
14487 } | 14482 } |
| 14483 |
| 14484 |
| 14485 // Regression test for issue 1470. |
| 14486 THREADED_TEST(ReadOnlyIndexedProperties) { |
| 14487 v8::HandleScope scope; |
| 14488 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 14489 |
| 14490 LocalContext context; |
| 14491 Local<v8::Object> obj = templ->NewInstance(); |
| 14492 context->Global()->Set(v8_str("obj"), obj); |
| 14493 obj->Set(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly); |
| 14494 obj->Set(v8_str("1"), v8_str("foobar")); |
| 14495 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1"))); |
| 14496 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); |
| 14497 obj->Set(v8_num(2), v8_str("foobar")); |
| 14498 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2))); |
| 14499 |
| 14500 // Test non-smi case. |
| 14501 obj->Set(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly); |
| 14502 obj->Set(v8_str("2000000000"), v8_str("foobar")); |
| 14503 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("2000000000"))); |
| 14504 } |
OLD | NEW |