| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 | 151 |
| 152 static StaticResource<SafeStringInputBuffer> safe_string_input_buffer; | 152 static StaticResource<SafeStringInputBuffer> safe_string_input_buffer; |
| 153 | 153 |
| 154 | 154 |
| 155 Handle<JSFunction> Compiler::Compile(Handle<String> source, | 155 Handle<JSFunction> Compiler::Compile(Handle<String> source, |
| 156 Handle<Object> script_name, | 156 Handle<Object> script_name, |
| 157 int line_offset, int column_offset, | 157 int line_offset, int column_offset, |
| 158 v8::Extension* extension, | 158 v8::Extension* extension, |
| 159 ScriptDataImpl* input_pre_data) { | 159 ScriptDataImpl* input_pre_data) { |
| 160 Counters::total_load_size.Increment(source->length()); | 160 int source_length = source->length(); |
| 161 Counters::total_compile_size.Increment(source->length()); | 161 Counters::total_load_size.Increment(source_length); |
| 162 Counters::total_compile_size.Increment(source_length); |
| 162 | 163 |
| 163 // The VM is in the COMPILER state until exiting this function. | 164 // The VM is in the COMPILER state until exiting this function. |
| 164 VMState state(COMPILER); | 165 VMState state(COMPILER); |
| 165 | 166 |
| 166 // Do a lookup in the compilation cache but not for extensions. | 167 // Do a lookup in the compilation cache but not for extensions. |
| 167 Handle<JSFunction> result; | 168 Handle<JSFunction> result; |
| 168 if (extension == NULL) { | 169 if (extension == NULL) { |
| 169 result = CompilationCache::LookupScript(source, | 170 result = CompilationCache::LookupScript(source, |
| 170 script_name, | 171 script_name, |
| 171 line_offset, | 172 line_offset, |
| 172 column_offset); | 173 column_offset); |
| 173 } | 174 } |
| 174 | 175 |
| 175 if (result.is_null()) { | 176 if (result.is_null()) { |
| 176 // No cache entry found. Do pre-parsing and compile the script. | 177 // No cache entry found. Do pre-parsing and compile the script. |
| 177 ScriptDataImpl* pre_data = input_pre_data; | 178 ScriptDataImpl* pre_data = input_pre_data; |
| 178 if (pre_data == NULL && source->length() >= FLAG_min_preparse_length) { | 179 if (pre_data == NULL && source_length >= FLAG_min_preparse_length) { |
| 179 Access<SafeStringInputBuffer> buf(&safe_string_input_buffer); | 180 Access<SafeStringInputBuffer> buf(&safe_string_input_buffer); |
| 180 buf->Reset(source.location()); | 181 buf->Reset(source.location()); |
| 181 pre_data = PreParse(buf.value(), extension); | 182 pre_data = PreParse(buf.value(), extension); |
| 182 } | 183 } |
| 183 | 184 |
| 184 // Create a script object describing the script to be compiled. | 185 // Create a script object describing the script to be compiled. |
| 185 Handle<Script> script = Factory::NewScript(source); | 186 Handle<Script> script = Factory::NewScript(source); |
| 186 if (!script_name.is_null()) { | 187 if (!script_name.is_null()) { |
| 187 script->set_name(*script_name); | 188 script->set_name(*script_name); |
| 188 script->set_line_offset(Smi::FromInt(line_offset)); | 189 script->set_line_offset(Smi::FromInt(line_offset)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 201 } | 202 } |
| 202 } | 203 } |
| 203 | 204 |
| 204 return result; | 205 return result; |
| 205 } | 206 } |
| 206 | 207 |
| 207 | 208 |
| 208 Handle<JSFunction> Compiler::CompileEval(Handle<String> source, | 209 Handle<JSFunction> Compiler::CompileEval(Handle<String> source, |
| 209 int line_offset, | 210 int line_offset, |
| 210 bool is_global) { | 211 bool is_global) { |
| 211 Counters::total_eval_size.Increment(source->length()); | 212 StringShape source_shape(*source); |
| 212 Counters::total_compile_size.Increment(source->length()); | 213 int source_length = source->length(source_shape); |
| 214 Counters::total_eval_size.Increment(source_length); |
| 215 Counters::total_compile_size.Increment(source_length); |
| 213 | 216 |
| 214 // The VM is in the COMPILER state until exiting this function. | 217 // The VM is in the COMPILER state until exiting this function. |
| 215 VMState state(COMPILER); | 218 VMState state(COMPILER); |
| 216 CompilationCache::Entry entry = is_global | 219 CompilationCache::Entry entry = is_global |
| 217 ? CompilationCache::EVAL_GLOBAL | 220 ? CompilationCache::EVAL_GLOBAL |
| 218 : CompilationCache::EVAL_CONTEXTUAL; | 221 : CompilationCache::EVAL_CONTEXTUAL; |
| 219 | 222 |
| 220 // Do a lookup in the compilation cache; if the entry is not there, | 223 // Do a lookup in the compilation cache; if the entry is not there, |
| 221 // invoke the compiler and add the result to the cache. | 224 // invoke the compiler and add the result to the cache. |
| 222 Handle<JSFunction> result = CompilationCache::LookupEval(source, entry); | 225 Handle<JSFunction> result = CompilationCache::LookupEval(source, entry); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 // Set the expected number of properties for instances. | 291 // Set the expected number of properties for instances. |
| 289 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); | 292 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
| 290 | 293 |
| 291 // Check the function has compiled code. | 294 // Check the function has compiled code. |
| 292 ASSERT(shared->is_compiled()); | 295 ASSERT(shared->is_compiled()); |
| 293 return true; | 296 return true; |
| 294 } | 297 } |
| 295 | 298 |
| 296 | 299 |
| 297 } } // namespace v8::internal | 300 } } // namespace v8::internal |
| OLD | NEW |