| OLD | NEW |
| 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 static int count_; | 177 static int count_; |
| 178 CcTest::TestFunction* callback_; | 178 CcTest::TestFunction* callback_; |
| 179 RegisterThreadedTest* prev_; | 179 RegisterThreadedTest* prev_; |
| 180 }; | 180 }; |
| 181 | 181 |
| 182 | 182 |
| 183 RegisterThreadedTest *RegisterThreadedTest::first_ = NULL; | 183 RegisterThreadedTest *RegisterThreadedTest::first_ = NULL; |
| 184 int RegisterThreadedTest::count_ = 0; | 184 int RegisterThreadedTest::count_ = 0; |
| 185 | 185 |
| 186 | 186 |
| 187 // Helper function that compiles and runs the source. |
| 188 static Local<Value> CompileRun(const char* source) { |
| 189 return Script::Compile(String::New(source))->Run(); |
| 190 } |
| 191 |
| 192 static void ExpectString(const char* code, const char* expected) { |
| 193 Local<Value> result = CompileRun(code); |
| 194 CHECK(result->IsString()); |
| 195 String::AsciiValue ascii(result); |
| 196 CHECK_EQ(expected, *ascii); |
| 197 } |
| 198 |
| 199 |
| 200 static void ExpectBoolean(const char* code, bool expected) { |
| 201 Local<Value> result = CompileRun(code); |
| 202 CHECK(result->IsBoolean()); |
| 203 CHECK_EQ(expected, result->BooleanValue()); |
| 204 } |
| 205 |
| 206 |
| 207 static void ExpectObject(const char* code, Local<Value> expected) { |
| 208 Local<Value> result = CompileRun(code); |
| 209 CHECK(result->Equals(expected)); |
| 210 } |
| 211 |
| 212 |
| 187 static int signature_callback_count; | 213 static int signature_callback_count; |
| 188 static v8::Handle<Value> IncrementingSignatureCallback( | 214 static v8::Handle<Value> IncrementingSignatureCallback( |
| 189 const v8::Arguments& args) { | 215 const v8::Arguments& args) { |
| 190 ApiTestFuzzer::Fuzz(); | 216 ApiTestFuzzer::Fuzz(); |
| 191 signature_callback_count++; | 217 signature_callback_count++; |
| 192 v8::Handle<v8::Array> result = v8::Array::New(args.Length()); | 218 v8::Handle<v8::Array> result = v8::Array::New(args.Length()); |
| 193 for (int i = 0; i < args.Length(); i++) | 219 for (int i = 0; i < args.Length(); i++) |
| 194 result->Set(v8::Integer::New(i), args[i]); | 220 result->Set(v8::Integer::New(i), args[i]); |
| 195 return result; | 221 return result; |
| 196 } | 222 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 224 | 250 |
| 225 const char* c_source = "1 + 2 + 3"; | 251 const char* c_source = "1 + 2 + 3"; |
| 226 Local<String> source = String::New(c_source); | 252 Local<String> source = String::New(c_source); |
| 227 Local<Script> script = Script::Compile(source); | 253 Local<Script> script = Script::Compile(source); |
| 228 CHECK_EQ(6, script->Run()->Int32Value()); | 254 CHECK_EQ(6, script->Run()->Int32Value()); |
| 229 | 255 |
| 230 local_env->Exit(); | 256 local_env->Exit(); |
| 231 } | 257 } |
| 232 | 258 |
| 233 | 259 |
| 234 // Helper function that compiles and runs the source. | |
| 235 static Local<Value> CompileRun(const char* source) { | |
| 236 return Script::Compile(String::New(source))->Run(); | |
| 237 } | |
| 238 | |
| 239 THREADED_TEST(ReceiverSignature) { | 260 THREADED_TEST(ReceiverSignature) { |
| 240 v8::HandleScope scope; | 261 v8::HandleScope scope; |
| 241 LocalContext env; | 262 LocalContext env; |
| 242 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); | 263 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); |
| 243 v8::Handle<v8::Signature> sig = v8::Signature::New(fun); | 264 v8::Handle<v8::Signature> sig = v8::Signature::New(fun); |
| 244 fun->PrototypeTemplate()->Set( | 265 fun->PrototypeTemplate()->Set( |
| 245 v8_str("m"), | 266 v8_str("m"), |
| 246 v8::FunctionTemplate::New(IncrementingSignatureCallback, | 267 v8::FunctionTemplate::New(IncrementingSignatureCallback, |
| 247 v8::Handle<Value>(), | 268 v8::Handle<Value>(), |
| 248 sig)); | 269 sig)); |
| (...skipping 2327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2576 CHECK_EQ(v8_num(5), result); | 2597 CHECK_EQ(v8_num(5), result); |
| 2577 result = setter_script->Run(); | 2598 result = setter_script->Run(); |
| 2578 CHECK_EQ(v8_num(23), result); | 2599 CHECK_EQ(v8_num(23), result); |
| 2579 result = interceptor_setter_script->Run(); | 2600 result = interceptor_setter_script->Run(); |
| 2580 CHECK_EQ(v8_num(23), result); | 2601 CHECK_EQ(v8_num(23), result); |
| 2581 result = interceptor_getter_script->Run(); | 2602 result = interceptor_getter_script->Run(); |
| 2582 CHECK_EQ(v8_num(625), result); | 2603 CHECK_EQ(v8_num(625), result); |
| 2583 } | 2604 } |
| 2584 | 2605 |
| 2585 | 2606 |
| 2607 static v8::Handle<Value> IdentityIndexedPropertyGetter( |
| 2608 uint32_t index, |
| 2609 const AccessorInfo& info) { |
| 2610 return v8::Integer::New(index); |
| 2611 } |
| 2612 |
| 2613 |
| 2614 THREADED_TEST(IndexedInterceptorWithNoSetter) { |
| 2615 v8::HandleScope scope; |
| 2616 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 2617 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
| 2618 |
| 2619 LocalContext context; |
| 2620 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 2621 |
| 2622 const char* code = |
| 2623 "try {" |
| 2624 " obj[0] = 239;" |
| 2625 " for (var i = 0; i < 100; i++) {" |
| 2626 " var v = obj[0];" |
| 2627 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;" |
| 2628 " }" |
| 2629 " 'PASSED'" |
| 2630 "} catch(e) {" |
| 2631 " e" |
| 2632 "}"; |
| 2633 ExpectString(code, "PASSED"); |
| 2634 } |
| 2635 |
| 2636 |
| 2586 THREADED_TEST(MultiContexts) { | 2637 THREADED_TEST(MultiContexts) { |
| 2587 v8::HandleScope scope; | 2638 v8::HandleScope scope; |
| 2588 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 2639 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); |
| 2589 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler)); | 2640 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler)); |
| 2590 | 2641 |
| 2591 Local<String> password = v8_str("Password"); | 2642 Local<String> password = v8_str("Password"); |
| 2592 | 2643 |
| 2593 // Create an environment | 2644 // Create an environment |
| 2594 LocalContext context0(0, templ); | 2645 LocalContext context0(0, templ); |
| 2595 context0->SetSecurityToken(password); | 2646 context0->SetSecurityToken(password); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2662 LocalContext env0; | 2713 LocalContext env0; |
| 2663 Local<Script> script0 = Script::Compile(source); | 2714 Local<Script> script0 = Script::Compile(source); |
| 2664 CHECK_EQ(8901.0, script0->Run()->NumberValue()); | 2715 CHECK_EQ(8901.0, script0->Run()->NumberValue()); |
| 2665 | 2716 |
| 2666 LocalContext env1; | 2717 LocalContext env1; |
| 2667 Local<Script> script1 = Script::Compile(source); | 2718 Local<Script> script1 = Script::Compile(source); |
| 2668 CHECK_EQ(8901.0, script1->Run()->NumberValue()); | 2719 CHECK_EQ(8901.0, script1->Run()->NumberValue()); |
| 2669 } | 2720 } |
| 2670 | 2721 |
| 2671 | 2722 |
| 2672 static void ExpectString(const char* code, const char* expected) { | |
| 2673 Local<Value> result = CompileRun(code); | |
| 2674 CHECK(result->IsString()); | |
| 2675 String::AsciiValue ascii(result); | |
| 2676 CHECK_EQ(0, strcmp(*ascii, expected)); | |
| 2677 } | |
| 2678 | |
| 2679 | |
| 2680 static void ExpectBoolean(const char* code, bool expected) { | |
| 2681 Local<Value> result = CompileRun(code); | |
| 2682 CHECK(result->IsBoolean()); | |
| 2683 CHECK_EQ(expected, result->BooleanValue()); | |
| 2684 } | |
| 2685 | |
| 2686 | |
| 2687 static void ExpectObject(const char* code, Local<Value> expected) { | |
| 2688 Local<Value> result = CompileRun(code); | |
| 2689 CHECK(result->Equals(expected)); | |
| 2690 } | |
| 2691 | |
| 2692 | |
| 2693 THREADED_TEST(UndetectableObject) { | 2723 THREADED_TEST(UndetectableObject) { |
| 2694 v8::HandleScope scope; | 2724 v8::HandleScope scope; |
| 2695 LocalContext env; | 2725 LocalContext env; |
| 2696 | 2726 |
| 2697 Local<v8::FunctionTemplate> desc = | 2727 Local<v8::FunctionTemplate> desc = |
| 2698 v8::FunctionTemplate::New(0, v8::Handle<Value>()); | 2728 v8::FunctionTemplate::New(0, v8::Handle<Value>()); |
| 2699 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable | 2729 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable |
| 2700 | 2730 |
| 2701 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); | 2731 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); |
| 2702 env->Global()->Set(v8_str("undetectable"), obj); | 2732 env->Global()->Set(v8_str("undetectable"), obj); |
| (...skipping 6102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8805 CompileRun(source_exception); | 8835 CompileRun(source_exception); |
| 8806 other_context->Exit(); | 8836 other_context->Exit(); |
| 8807 v8::internal::Heap::CollectAllGarbage(false); | 8837 v8::internal::Heap::CollectAllGarbage(false); |
| 8808 if (GetGlobalObjectsCount() == 1) break; | 8838 if (GetGlobalObjectsCount() == 1) break; |
| 8809 } | 8839 } |
| 8810 CHECK_GE(2, gc_count); | 8840 CHECK_GE(2, gc_count); |
| 8811 CHECK_EQ(1, GetGlobalObjectsCount()); | 8841 CHECK_EQ(1, GetGlobalObjectsCount()); |
| 8812 | 8842 |
| 8813 other_context.Dispose(); | 8843 other_context.Dispose(); |
| 8814 } | 8844 } |
| OLD | NEW |