OLD | NEW |
1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 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 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 { | 1155 { |
1156 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); | 1156 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); |
1157 script = v8::ScriptCompiler::CompileUnbound( | 1157 script = v8::ScriptCompiler::CompileUnbound( |
1158 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); | 1158 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); |
1159 } | 1159 } |
1160 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 1160 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
1161 CHECK(result->ToString()->Equals(v8_str("abcdef"))); | 1161 CHECK(result->ToString()->Equals(v8_str("abcdef"))); |
1162 } | 1162 } |
1163 isolate2->Dispose(); | 1163 isolate2->Dispose(); |
1164 } | 1164 } |
| 1165 |
| 1166 |
| 1167 TEST(Bug3628) { |
| 1168 FLAG_serialize_toplevel = true; |
| 1169 FLAG_harmony_scoping = true; |
| 1170 |
| 1171 const char* source1 = "'use strict'; let x = 'X'"; |
| 1172 const char* source2 = "'use strict'; let y = 'Y'"; |
| 1173 const char* source3 = "'use strict'; x + y"; |
| 1174 |
| 1175 v8::ScriptCompiler::CachedData* cache; |
| 1176 |
| 1177 v8::Isolate* isolate1 = v8::Isolate::New(); |
| 1178 { |
| 1179 v8::Isolate::Scope iscope(isolate1); |
| 1180 v8::HandleScope scope(isolate1); |
| 1181 v8::Local<v8::Context> context = v8::Context::New(isolate1); |
| 1182 v8::Context::Scope context_scope(context); |
| 1183 |
| 1184 CompileRun(source1); |
| 1185 CompileRun(source2); |
| 1186 |
| 1187 v8::Local<v8::String> source_str = v8_str(source3); |
| 1188 v8::ScriptOrigin origin(v8_str("test")); |
| 1189 v8::ScriptCompiler::Source source(source_str, origin); |
| 1190 v8::Local<v8::UnboundScript> script = v8::ScriptCompiler::CompileUnbound( |
| 1191 isolate1, &source, v8::ScriptCompiler::kProduceCodeCache); |
| 1192 const v8::ScriptCompiler::CachedData* data = source.GetCachedData(); |
| 1193 CHECK(data); |
| 1194 // Persist cached data. |
| 1195 uint8_t* buffer = NewArray<uint8_t>(data->length); |
| 1196 MemCopy(buffer, data->data, data->length); |
| 1197 cache = new v8::ScriptCompiler::CachedData( |
| 1198 buffer, data->length, v8::ScriptCompiler::CachedData::BufferOwned); |
| 1199 |
| 1200 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
| 1201 CHECK(result->ToString()->Equals(v8_str("XY"))); |
| 1202 } |
| 1203 isolate1->Dispose(); |
| 1204 |
| 1205 v8::Isolate* isolate2 = v8::Isolate::New(); |
| 1206 { |
| 1207 v8::Isolate::Scope iscope(isolate2); |
| 1208 v8::HandleScope scope(isolate2); |
| 1209 v8::Local<v8::Context> context = v8::Context::New(isolate2); |
| 1210 v8::Context::Scope context_scope(context); |
| 1211 |
| 1212 // Reverse order of prior running scripts. |
| 1213 CompileRun(source2); |
| 1214 CompileRun(source1); |
| 1215 |
| 1216 v8::Local<v8::String> source_str = v8_str(source3); |
| 1217 v8::ScriptOrigin origin(v8_str("test")); |
| 1218 v8::ScriptCompiler::Source source(source_str, origin, cache); |
| 1219 v8::Local<v8::UnboundScript> script; |
| 1220 { |
| 1221 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); |
| 1222 script = v8::ScriptCompiler::CompileUnbound( |
| 1223 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); |
| 1224 } |
| 1225 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
| 1226 CHECK(result->ToString()->Equals(v8_str("XY"))); |
| 1227 } |
| 1228 isolate2->Dispose(); |
| 1229 } |
OLD | NEW |