| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #include "src/objects.h" | 5 #include "src/objects.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <iomanip> | 8 #include <iomanip> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 13343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13354 return isolate->factory()->NewSubString( | 13354 return isolate->factory()->NewSubString( |
| 13355 script_source, Handle<Smi>::cast(class_start_position)->value(), | 13355 script_source, Handle<Smi>::cast(class_start_position)->value(), |
| 13356 Handle<Smi>::cast(class_end_position)->value()); | 13356 Handle<Smi>::cast(class_end_position)->value()); |
| 13357 } | 13357 } |
| 13358 | 13358 |
| 13359 // Check if we have source code for the {function}. | 13359 // Check if we have source code for the {function}. |
| 13360 if (!shared_info->HasSourceCode()) { | 13360 if (!shared_info->HasSourceCode()) { |
| 13361 return NativeCodeFunctionSourceString(shared_info); | 13361 return NativeCodeFunctionSourceString(shared_info); |
| 13362 } | 13362 } |
| 13363 | 13363 |
| 13364 if (FLAG_harmony_function_tostring) { |
| 13365 return Handle<String>::cast(shared_info->GetSourceCodeHarmony()); |
| 13366 } |
| 13367 |
| 13364 IncrementalStringBuilder builder(isolate); | 13368 IncrementalStringBuilder builder(isolate); |
| 13365 FunctionKind kind = shared_info->kind(); | 13369 FunctionKind kind = shared_info->kind(); |
| 13366 if (!IsArrowFunction(kind)) { | 13370 if (!IsArrowFunction(kind)) { |
| 13367 if (IsConciseMethod(kind)) { | 13371 if (IsConciseMethod(kind)) { |
| 13368 if (IsGeneratorFunction(kind)) { | 13372 if (IsGeneratorFunction(kind)) { |
| 13369 builder.AppendCharacter('*'); | 13373 builder.AppendCharacter('*'); |
| 13370 } else if (IsAsyncFunction(kind)) { | 13374 } else if (IsAsyncFunction(kind)) { |
| 13371 builder.AppendCString("async "); | 13375 builder.AppendCString("async "); |
| 13372 } | 13376 } |
| 13373 } else { | 13377 } else { |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13792 } | 13796 } |
| 13793 | 13797 |
| 13794 | 13798 |
| 13795 Handle<Object> SharedFunctionInfo::GetSourceCode() { | 13799 Handle<Object> SharedFunctionInfo::GetSourceCode() { |
| 13796 if (!HasSourceCode()) return GetIsolate()->factory()->undefined_value(); | 13800 if (!HasSourceCode()) return GetIsolate()->factory()->undefined_value(); |
| 13797 Handle<String> source(String::cast(Script::cast(script())->source())); | 13801 Handle<String> source(String::cast(Script::cast(script())->source())); |
| 13798 return GetIsolate()->factory()->NewSubString( | 13802 return GetIsolate()->factory()->NewSubString( |
| 13799 source, start_position(), end_position()); | 13803 source, start_position(), end_position()); |
| 13800 } | 13804 } |
| 13801 | 13805 |
| 13806 Handle<Object> SharedFunctionInfo::GetSourceCodeHarmony() { |
| 13807 Isolate* isolate = GetIsolate(); |
| 13808 if (!HasSourceCode()) return isolate->factory()->undefined_value(); |
| 13809 Handle<String> script_source(String::cast(Script::cast(script())->source())); |
| 13810 int start_pos = function_token_position(); |
| 13811 if (start_pos == kNoSourcePosition) start_pos = start_position(); |
| 13812 return isolate->factory()->NewSubString(script_source, start_pos, |
| 13813 end_position()); |
| 13814 } |
| 13802 | 13815 |
| 13803 bool SharedFunctionInfo::IsInlineable() { | 13816 bool SharedFunctionInfo::IsInlineable() { |
| 13804 // Check that the function has a script associated with it. | 13817 // Check that the function has a script associated with it. |
| 13805 if (!script()->IsScript()) return false; | 13818 if (!script()->IsScript()) return false; |
| 13806 return !optimization_disabled(); | 13819 return !optimization_disabled(); |
| 13807 } | 13820 } |
| 13808 | 13821 |
| 13809 | 13822 |
| 13810 int SharedFunctionInfo::SourceSize() { | 13823 int SharedFunctionInfo::SourceSize() { |
| 13811 return end_position() - start_position(); | 13824 return end_position() - start_position(); |
| (...skipping 6704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20516 // depend on this. | 20529 // depend on this. |
| 20517 return DICTIONARY_ELEMENTS; | 20530 return DICTIONARY_ELEMENTS; |
| 20518 } | 20531 } |
| 20519 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20532 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
| 20520 return kind; | 20533 return kind; |
| 20521 } | 20534 } |
| 20522 } | 20535 } |
| 20523 | 20536 |
| 20524 } // namespace internal | 20537 } // namespace internal |
| 20525 } // namespace v8 | 20538 } // namespace v8 |
| OLD | NEW |