OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 5571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5582 v8::Utils::OpenHandle(*global_template); | 5582 v8::Utils::OpenHandle(*global_template); |
5583 CHECK(!internal_template->constructor()->IsUndefined()); | 5583 CHECK(!internal_template->constructor()->IsUndefined()); |
5584 i::Handle<i::FunctionTemplateInfo> constructor( | 5584 i::Handle<i::FunctionTemplateInfo> constructor( |
5585 i::FunctionTemplateInfo::cast(internal_template->constructor())); | 5585 i::FunctionTemplateInfo::cast(internal_template->constructor())); |
5586 CHECK(!constructor->access_check_info()->IsUndefined()); | 5586 CHECK(!constructor->access_check_info()->IsUndefined()); |
5587 v8::Persistent<Context> context0 = Context::New(NULL, global_template); | 5587 v8::Persistent<Context> context0 = Context::New(NULL, global_template); |
5588 CHECK(!constructor->access_check_info()->IsUndefined()); | 5588 CHECK(!constructor->access_check_info()->IsUndefined()); |
5589 } | 5589 } |
5590 | 5590 |
5591 | 5591 |
5592 static String::ExternalStringResource* SymbolCallback(const char* chars, | |
5593 size_t length) { | |
5594 uint16_t* buffer = i::NewArray<uint16_t>(length + 1); | |
5595 for (size_t i = 0; i < length; i++) { | |
5596 buffer[i] = chars[i]; | |
5597 } | |
5598 buffer[length] = '\0'; | |
5599 return new TestResource(buffer); | |
5600 } | |
5601 | |
5602 | |
5603 static v8::Handle<Value> ExternalSymbolGetter(Local<String> name, | |
5604 const AccessorInfo& info) { | |
5605 ApiTestFuzzer::Fuzz(); | |
5606 CHECK(!name->Equals(v8_str("externalSymbol722")) || name->IsExternal()); | |
5607 return v8::True(); | |
5608 } | |
5609 | |
5610 | |
5611 static void ExternalSymbolSetter(Local<String> name, | |
5612 Local<Value> value, | |
5613 const AccessorInfo&) { | |
5614 ApiTestFuzzer::Fuzz(); | |
5615 CHECK(!name->Equals(v8_str("externalSymbol722")) || name->IsExternal()); | |
5616 } | |
5617 | |
5618 | |
5619 THREADED_TEST(ExternalSymbols) { | |
5620 TestResource::dispose_count = 0; | |
5621 v8::V8::SetExternalSymbolCallback(SymbolCallback); | |
5622 v8::HandleScope scope; | |
5623 LocalContext context; | |
5624 Local<ObjectTemplate> templ = ObjectTemplate::New(); | |
5625 // Use a bizare name so that the name does not clash with names used | |
5626 // in natives files. If running with snapshots enabled, variable | |
5627 // names used in the native files will be normal symbols instead of | |
5628 // external ones. Also, make sure that the bizare name is used from | |
5629 // JavaScript code before using it from C++ code. | |
5630 Local<Value> value = | |
5631 CompileRun("var o = { externalSymbol722: 42 }; o.externalSymbol722"); | |
5632 CHECK_EQ(42, value->Int32Value()); | |
5633 templ->SetAccessor(v8_str("externalSymbol722"), | |
5634 ExternalSymbolGetter, | |
5635 ExternalSymbolSetter); | |
5636 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | |
5637 value = CompileRun("obj.externalSymbol722"); | |
5638 CHECK_EQ(true, value->BooleanValue()); | |
5639 value = CompileRun("obj.externalSymbol722 = 42"); | |
5640 v8::V8::SetExternalSymbolCallback(NULL); | |
5641 } | |
5642 | |
5643 | |
5644 // This test verifies that pre-compilation (aka preparsing) can be called | 5592 // This test verifies that pre-compilation (aka preparsing) can be called |
5645 // without initializing the whole VM. Thus we cannot run this test in a | 5593 // without initializing the whole VM. Thus we cannot run this test in a |
5646 // multi-threaded setup. | 5594 // multi-threaded setup. |
5647 TEST(PreCompile) { | 5595 TEST(PreCompile) { |
5648 // TODO(155): This test would break without the initialization of V8. This is | 5596 // TODO(155): This test would break without the initialization of V8. This is |
5649 // a workaround for now to make this test not fail. | 5597 // a workaround for now to make this test not fail. |
5650 v8::V8::Initialize(); | 5598 v8::V8::Initialize(); |
5651 const char *script = "function foo(a) { return a+1; }"; | 5599 const char *script = "function foo(a) { return a+1; }"; |
5652 v8::ScriptData *sd = v8::ScriptData::PreCompile(script, strlen(script)); | 5600 v8::ScriptData *sd = v8::ScriptData::PreCompile(script, strlen(script)); |
5653 CHECK_NE(sd->Length(), 0); | 5601 CHECK_NE(sd->Length(), 0); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5703 context1->Global()->Set(v8_str("other"), context0->Global()); | 5651 context1->Global()->Set(v8_str("other"), context0->Global()); |
5704 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); | 5652 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); |
5705 CHECK(value->IsInt32()); | 5653 CHECK(value->IsInt32()); |
5706 CHECK_EQ(42, value->Int32Value()); | 5654 CHECK_EQ(42, value->Int32Value()); |
5707 context1->Exit(); | 5655 context1->Exit(); |
5708 | 5656 |
5709 // Dispose the contexts to allow them to be garbage collected. | 5657 // Dispose the contexts to allow them to be garbage collected. |
5710 context0.Dispose(); | 5658 context0.Dispose(); |
5711 context1.Dispose(); | 5659 context1.Dispose(); |
5712 } | 5660 } |
OLD | NEW |