Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 // Defined when linking against shared lib on Windows. | 6 // Defined when linking against shared lib on Windows. |
| 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) | 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) |
| 8 #define V8_SHARED | 8 #define V8_SHARED |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 } | 170 } |
| 171 #endif // !V8_SHARED | 171 #endif // !V8_SHARED |
| 172 | 172 |
| 173 | 173 |
| 174 // Converts a V8 value to a C string. | 174 // Converts a V8 value to a C string. |
| 175 const char* Shell::ToCString(const v8::String::Utf8Value& value) { | 175 const char* Shell::ToCString(const v8::String::Utf8Value& value) { |
| 176 return *value ? *value : "<string conversion failed>"; | 176 return *value ? *value : "<string conversion failed>"; |
| 177 } | 177 } |
| 178 | 178 |
| 179 | 179 |
| 180 ScriptCompiler::CachedData* Shell::CompileCachedData( | |
|
vogelheim
2014/10/20 16:27:51
nitpick: I suspect this shouldn't be used outside
vogelheim
2014/10/20 16:27:52
naming nitpick: CompileForCachedData?
(You're not
| |
| 181 Local<String> source, Local<Value> name, | |
| 182 ScriptCompiler::CompileOptions compile_options) { | |
| 183 int source_length = source->Length(); | |
| 184 uint16_t* source_buffer = new uint16_t[source_length]; | |
| 185 source->Write(source_buffer, 0, source_length); | |
| 186 int name_length = 0; | |
| 187 uint16_t* name_buffer = NULL; | |
| 188 if (name->IsString()) { | |
| 189 Local<String> name_string = name->ToString(); | |
| 190 name_length = name_string->Length(); | |
| 191 name_buffer = new uint16_t[name_length]; | |
| 192 name_string->Write(name_buffer, 0, name_length); | |
| 193 } | |
| 194 Isolate* temp_isolate = Isolate::New(); | |
| 195 ScriptCompiler::CachedData* result = NULL; | |
| 196 { | |
| 197 Isolate::Scope isolate_scope(temp_isolate); | |
| 198 HandleScope handle_scope(temp_isolate); | |
| 199 Context::Scope context_scope(Context::New(temp_isolate)); | |
| 200 Local<String> source_copy = v8::String::NewFromTwoByte( | |
| 201 temp_isolate, source_buffer, v8::String::kNormalString, source_length); | |
| 202 Local<Value> name_copy; | |
| 203 if (name_buffer) { | |
| 204 name_copy = v8::String::NewFromTwoByte( | |
| 205 temp_isolate, name_buffer, v8::String::kNormalString, name_length); | |
| 206 } else { | |
| 207 name_copy = v8::Undefined(temp_isolate); | |
| 208 } | |
| 209 ScriptCompiler::Source script_source(source_copy, ScriptOrigin(name_copy)); | |
| 210 ScriptCompiler::CompileUnbound(temp_isolate, &script_source, | |
| 211 compile_options); | |
| 212 if (script_source.GetCachedData()) { | |
| 213 int length = script_source.GetCachedData()->length; | |
| 214 uint8_t* cache = new uint8_t[length]; | |
| 215 memcpy(cache, script_source.GetCachedData()->data, length); | |
| 216 result = new ScriptCompiler::CachedData( | |
| 217 cache, length, ScriptCompiler::CachedData::BufferOwned); | |
| 218 } | |
| 219 } | |
| 220 temp_isolate->Dispose(); | |
| 221 delete[] source_buffer; | |
| 222 return result; | |
| 223 } | |
| 224 | |
| 225 | |
| 180 // Compile a string within the current v8 context. | 226 // Compile a string within the current v8 context. |
| 181 Local<UnboundScript> Shell::CompileString( | 227 Local<UnboundScript> Shell::CompileString( |
| 182 Isolate* isolate, Local<String> source, Local<Value> name, | 228 Isolate* isolate, Local<String> source, Local<Value> name, |
| 183 v8::ScriptCompiler::CompileOptions compile_options) { | 229 ScriptCompiler::CompileOptions compile_options) { |
| 184 ScriptOrigin origin(name); | 230 ScriptOrigin origin(name); |
| 185 ScriptCompiler::Source script_source(source, origin); | 231 if (compile_options == ScriptCompiler::kNoCompileOptions) { |
| 186 Local<UnboundScript> script = | 232 ScriptCompiler::Source script_source(source, origin); |
| 187 ScriptCompiler::CompileUnbound(isolate, &script_source, compile_options); | 233 return ScriptCompiler::CompileUnbound(isolate, &script_source, |
| 234 compile_options); | |
| 235 } | |
| 188 | 236 |
| 189 // Was caching requested & successful? Then compile again, now with cache. | 237 ScriptCompiler::CachedData* data = |
| 190 if (script_source.GetCachedData()) { | 238 CompileCachedData(source, name, compile_options); |
| 191 if (compile_options == ScriptCompiler::kProduceCodeCache) { | 239 ScriptCompiler::Source cached_source(source, origin, data); |
| 192 compile_options = ScriptCompiler::kConsumeCodeCache; | 240 if (compile_options == ScriptCompiler::kProduceCodeCache) { |
| 193 } else if (compile_options == ScriptCompiler::kProduceParserCache) { | 241 compile_options = ScriptCompiler::kConsumeCodeCache; |
| 194 compile_options = ScriptCompiler::kConsumeParserCache; | 242 } else if (compile_options == ScriptCompiler::kProduceParserCache) { |
| 195 } else { | 243 compile_options = ScriptCompiler::kConsumeParserCache; |
| 196 DCHECK(false); // A new compile option? | 244 } else { |
| 197 } | 245 DCHECK(false); // A new compile option? |
| 198 ScriptCompiler::Source cached_source( | |
| 199 source, origin, new v8::ScriptCompiler::CachedData( | |
| 200 script_source.GetCachedData()->data, | |
| 201 script_source.GetCachedData()->length, | |
| 202 v8::ScriptCompiler::CachedData::BufferNotOwned)); | |
| 203 script = ScriptCompiler::CompileUnbound(isolate, &cached_source, | |
| 204 compile_options); | |
| 205 } | 246 } |
| 206 return script; | 247 if (data == NULL) compile_options = ScriptCompiler::kNoCompileOptions; |
| 248 return ScriptCompiler::CompileUnbound(isolate, &cached_source, | |
| 249 compile_options); | |
| 207 } | 250 } |
| 208 | 251 |
| 209 | 252 |
| 210 // Executes a string within the current v8 context. | 253 // Executes a string within the current v8 context. |
| 211 bool Shell::ExecuteString(Isolate* isolate, | 254 bool Shell::ExecuteString(Isolate* isolate, |
| 212 Handle<String> source, | 255 Handle<String> source, |
| 213 Handle<Value> name, | 256 Handle<Value> name, |
| 214 bool print_result, | 257 bool print_result, |
| 215 bool report_exceptions) { | 258 bool report_exceptions) { |
| 216 #ifndef V8_SHARED | 259 #ifndef V8_SHARED |
| (...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1721 } | 1764 } |
| 1722 | 1765 |
| 1723 } // namespace v8 | 1766 } // namespace v8 |
| 1724 | 1767 |
| 1725 | 1768 |
| 1726 #ifndef GOOGLE3 | 1769 #ifndef GOOGLE3 |
| 1727 int main(int argc, char* argv[]) { | 1770 int main(int argc, char* argv[]) { |
| 1728 return v8::Shell::Main(argc, argv); | 1771 return v8::Shell::Main(argc, argv); |
| 1729 } | 1772 } |
| 1730 #endif | 1773 #endif |
| OLD | NEW |