| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 } | 236 } |
| 237 | 237 |
| 238 | 238 |
| 239 static StaticResource<SafeStringInputBuffer> safe_string_input_buffer; | 239 static StaticResource<SafeStringInputBuffer> safe_string_input_buffer; |
| 240 | 240 |
| 241 | 241 |
| 242 Handle<JSFunction> Compiler::Compile(Handle<String> source, | 242 Handle<JSFunction> Compiler::Compile(Handle<String> source, |
| 243 Handle<Object> script_name, | 243 Handle<Object> script_name, |
| 244 int line_offset, int column_offset, | 244 int line_offset, int column_offset, |
| 245 v8::Extension* extension, | 245 v8::Extension* extension, |
| 246 ScriptDataImpl* input_pre_data) { | 246 ScriptDataImpl* input_pre_data, |
| 247 NativesFlag natives) { |
| 247 int source_length = source->length(); | 248 int source_length = source->length(); |
| 248 Counters::total_load_size.Increment(source_length); | 249 Counters::total_load_size.Increment(source_length); |
| 249 Counters::total_compile_size.Increment(source_length); | 250 Counters::total_compile_size.Increment(source_length); |
| 250 | 251 |
| 251 // The VM is in the COMPILER state until exiting this function. | 252 // The VM is in the COMPILER state until exiting this function. |
| 252 VMState state(COMPILER); | 253 VMState state(COMPILER); |
| 253 | 254 |
| 254 // Do a lookup in the compilation cache but not for extensions. | 255 // Do a lookup in the compilation cache but not for extensions. |
| 255 Handle<JSFunction> result; | 256 Handle<JSFunction> result; |
| 256 if (extension == NULL) { | 257 if (extension == NULL) { |
| 257 result = CompilationCache::LookupScript(source, | 258 result = CompilationCache::LookupScript(source, |
| 258 script_name, | 259 script_name, |
| 259 line_offset, | 260 line_offset, |
| 260 column_offset); | 261 column_offset); |
| 261 } | 262 } |
| 262 | 263 |
| 263 if (result.is_null()) { | 264 if (result.is_null()) { |
| 264 // No cache entry found. Do pre-parsing and compile the script. | 265 // No cache entry found. Do pre-parsing and compile the script. |
| 265 ScriptDataImpl* pre_data = input_pre_data; | 266 ScriptDataImpl* pre_data = input_pre_data; |
| 266 if (pre_data == NULL && source_length >= FLAG_min_preparse_length) { | 267 if (pre_data == NULL && source_length >= FLAG_min_preparse_length) { |
| 267 Access<SafeStringInputBuffer> buf(&safe_string_input_buffer); | 268 Access<SafeStringInputBuffer> buf(&safe_string_input_buffer); |
| 268 buf->Reset(source.location()); | 269 buf->Reset(source.location()); |
| 269 pre_data = PreParse(source, buf.value(), extension); | 270 pre_data = PreParse(source, buf.value(), extension); |
| 270 } | 271 } |
| 271 | 272 |
| 272 // Create a script object describing the script to be compiled. | 273 // Create a script object describing the script to be compiled. |
| 273 Handle<Script> script = Factory::NewScript(source); | 274 Handle<Script> script = Factory::NewScript(source); |
| 275 if (natives == NATIVES_CODE) { |
| 276 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
| 277 } |
| 274 if (!script_name.is_null()) { | 278 if (!script_name.is_null()) { |
| 275 script->set_name(*script_name); | 279 script->set_name(*script_name); |
| 276 script->set_line_offset(Smi::FromInt(line_offset)); | 280 script->set_line_offset(Smi::FromInt(line_offset)); |
| 277 script->set_column_offset(Smi::FromInt(column_offset)); | 281 script->set_column_offset(Smi::FromInt(column_offset)); |
| 278 } | 282 } |
| 279 | 283 |
| 280 // Compile the function and add it to the cache. | 284 // Compile the function and add it to the cache. |
| 281 result = MakeFunction(true, | 285 result = MakeFunction(true, |
| 282 false, | 286 false, |
| 283 DONT_VALIDATE_JSON, | 287 DONT_VALIDATE_JSON, |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 fun->shared()->set_is_toplevel(is_toplevel); | 560 fun->shared()->set_is_toplevel(is_toplevel); |
| 557 fun->shared()->set_inferred_name(*lit->inferred_name()); | 561 fun->shared()->set_inferred_name(*lit->inferred_name()); |
| 558 fun->shared()->SetThisPropertyAssignmentsInfo( | 562 fun->shared()->SetThisPropertyAssignmentsInfo( |
| 559 lit->has_only_simple_this_property_assignments(), | 563 lit->has_only_simple_this_property_assignments(), |
| 560 *lit->this_property_assignments()); | 564 *lit->this_property_assignments()); |
| 561 fun->shared()->set_try_full_codegen(lit->try_full_codegen()); | 565 fun->shared()->set_try_full_codegen(lit->try_full_codegen()); |
| 562 } | 566 } |
| 563 | 567 |
| 564 | 568 |
| 565 } } // namespace v8::internal | 569 } } // namespace v8::internal |
| OLD | NEW |