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 21069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21080 CHECK_EQ(false, try_catch.HasCaught()); | 21080 CHECK_EQ(false, try_catch.HasCaught()); |
21081 | 21081 |
21082 // Running the script exposes the error. | 21082 // Running the script exposes the error. |
21083 v8::Handle<Value> result(script->Run()); | 21083 v8::Handle<Value> result(script->Run()); |
21084 CHECK(result.IsEmpty()); | 21084 CHECK(result.IsEmpty()); |
21085 CHECK(try_catch.HasCaught()); | 21085 CHECK(try_catch.HasCaught()); |
21086 delete[] full_source; | 21086 delete[] full_source; |
21087 } | 21087 } |
21088 | 21088 |
21089 | 21089 |
| 21090 TEST(CodeCache) { |
| 21091 v8::Isolate::CreateParams create_params; |
| 21092 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 21093 |
| 21094 const char* source = "Math.sqrt(4)"; |
| 21095 const char* origin = "code cache test"; |
| 21096 v8::ScriptCompiler::CachedData* cache; |
| 21097 |
| 21098 v8::Isolate* isolate1 = v8::Isolate::New(create_params); |
| 21099 { |
| 21100 v8::Isolate::Scope iscope(isolate1); |
| 21101 v8::HandleScope scope(isolate1); |
| 21102 v8::Local<v8::Context> context = v8::Context::New(isolate1); |
| 21103 v8::Context::Scope cscope(context); |
| 21104 v8::Local<v8::String> source_string = v8_str(source); |
| 21105 v8::ScriptOrigin script_origin(v8_str(origin)); |
| 21106 v8::ScriptCompiler::Source source(source_string, script_origin); |
| 21107 v8::ScriptCompiler::CompileOptions option = |
| 21108 v8::ScriptCompiler::kProduceCodeCache; |
| 21109 v8::ScriptCompiler::Compile(context, &source, option).ToLocalChecked(); |
| 21110 int length = source.GetCachedData()->length; |
| 21111 uint8_t* cache_data = new uint8_t[length]; |
| 21112 memcpy(cache_data, source.GetCachedData()->data, length); |
| 21113 cache = new v8::ScriptCompiler::CachedData( |
| 21114 cache_data, length, v8::ScriptCompiler::CachedData::BufferOwned); |
| 21115 } |
| 21116 isolate1->Dispose(); |
| 21117 |
| 21118 v8::Isolate* isolate2 = v8::Isolate::New(create_params); |
| 21119 { |
| 21120 v8::Isolate::Scope iscope(isolate2); |
| 21121 v8::HandleScope scope(isolate2); |
| 21122 v8::Local<v8::Context> context = v8::Context::New(isolate2); |
| 21123 v8::Context::Scope cscope(context); |
| 21124 v8::Local<v8::String> source_string = v8_str(source); |
| 21125 v8::ScriptOrigin script_origin(v8_str(origin)); |
| 21126 v8::ScriptCompiler::Source source(source_string, script_origin, cache); |
| 21127 v8::ScriptCompiler::CompileOptions option = |
| 21128 v8::ScriptCompiler::kConsumeCodeCache; |
| 21129 v8::Local<v8::Script> script; |
| 21130 { |
| 21131 i::DisallowCompilation no_compile( |
| 21132 reinterpret_cast<i::Isolate*>(isolate2)); |
| 21133 script = v8::ScriptCompiler::Compile(context, &source, option) |
| 21134 .ToLocalChecked(); |
| 21135 } |
| 21136 CHECK_EQ(2, script->Run()->ToInt32(isolate2)->Int32Value()); |
| 21137 } |
| 21138 isolate2->Dispose(); |
| 21139 } |
| 21140 |
| 21141 |
21090 void TestInvalidCacheData(v8::ScriptCompiler::CompileOptions option) { | 21142 void TestInvalidCacheData(v8::ScriptCompiler::CompileOptions option) { |
21091 const char* garbage = "garbage garbage garbage garbage garbage garbage"; | 21143 const char* garbage = "garbage garbage garbage garbage garbage garbage"; |
21092 const uint8_t* data = reinterpret_cast<const uint8_t*>(garbage); | 21144 const uint8_t* data = reinterpret_cast<const uint8_t*>(garbage); |
21093 int length = 16; | 21145 int length = 16; |
21094 v8::ScriptCompiler::CachedData* cached_data = | 21146 v8::ScriptCompiler::CachedData* cached_data = |
21095 new v8::ScriptCompiler::CachedData(data, length); | 21147 new v8::ScriptCompiler::CachedData(data, length); |
21096 DCHECK(!cached_data->rejected); | 21148 DCHECK(!cached_data->rejected); |
21097 v8::ScriptOrigin origin(v8_str("origin")); | 21149 v8::ScriptOrigin origin(v8_str("origin")); |
21098 v8::ScriptCompiler::Source source(v8_str("42"), origin, cached_data); | 21150 v8::ScriptCompiler::Source source(v8_str("42"), origin, cached_data); |
21099 v8::Handle<v8::Script> script = | 21151 v8::Handle<v8::Script> script = |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21553 CHECK_EQ(2U, set->Size()); | 21605 CHECK_EQ(2U, set->Size()); |
21554 | 21606 |
21555 v8::Local<v8::Array> keys = set->AsArray(); | 21607 v8::Local<v8::Array> keys = set->AsArray(); |
21556 CHECK_EQ(2U, keys->Length()); | 21608 CHECK_EQ(2U, keys->Length()); |
21557 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); | 21609 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); |
21558 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); | 21610 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); |
21559 | 21611 |
21560 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); | 21612 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); |
21561 CHECK_EQ(2U, set->Size()); | 21613 CHECK_EQ(2U, set->Size()); |
21562 } | 21614 } |
OLD | NEW |