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 <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 12579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12590 return isolate->factory()->NewSubString( | 12590 return isolate->factory()->NewSubString( |
12591 script_source, Handle<Smi>::cast(class_start_position)->value(), | 12591 script_source, Handle<Smi>::cast(class_start_position)->value(), |
12592 Handle<Smi>::cast(class_end_position)->value()); | 12592 Handle<Smi>::cast(class_end_position)->value()); |
12593 } | 12593 } |
12594 | 12594 |
12595 // Check if we have source code for the {function}. | 12595 // Check if we have source code for the {function}. |
12596 if (!shared_info->HasSourceCode()) { | 12596 if (!shared_info->HasSourceCode()) { |
12597 return NativeCodeFunctionSourceString(shared_info); | 12597 return NativeCodeFunctionSourceString(shared_info); |
12598 } | 12598 } |
12599 | 12599 |
12600 if (FLAG_harmony_function_tostring) { | |
12601 return Handle<String>::cast(shared_info->GetSourceCodeHarmony()); | |
12602 } | |
12600 IncrementalStringBuilder builder(isolate); | 12603 IncrementalStringBuilder builder(isolate); |
12601 if (!shared_info->is_arrow()) { | 12604 if (!shared_info->is_arrow()) { |
12602 if (shared_info->is_concise_method()) { | 12605 if (shared_info->is_concise_method()) { |
12603 if (shared_info->is_generator()) { | 12606 if (shared_info->is_generator()) { |
12604 builder.AppendCharacter('*'); | 12607 builder.AppendCharacter('*'); |
12605 } else if (shared_info->is_async()) { | 12608 } else if (shared_info->is_async()) { |
12606 builder.AppendCString("async "); | 12609 builder.AppendCString("async "); |
12607 } | 12610 } |
12608 } else { | 12611 } else { |
12609 if (shared_info->is_generator()) { | 12612 if (shared_info->is_generator()) { |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13014 } | 13017 } |
13015 | 13018 |
13016 | 13019 |
13017 Handle<Object> SharedFunctionInfo::GetSourceCode() { | 13020 Handle<Object> SharedFunctionInfo::GetSourceCode() { |
13018 if (!HasSourceCode()) return GetIsolate()->factory()->undefined_value(); | 13021 if (!HasSourceCode()) return GetIsolate()->factory()->undefined_value(); |
13019 Handle<String> source(String::cast(Script::cast(script())->source())); | 13022 Handle<String> source(String::cast(Script::cast(script())->source())); |
13020 return GetIsolate()->factory()->NewSubString( | 13023 return GetIsolate()->factory()->NewSubString( |
13021 source, start_position(), end_position()); | 13024 source, start_position(), end_position()); |
13022 } | 13025 } |
13023 | 13026 |
13027 namespace { | |
13028 template <typename Char> | |
13029 Handle<Object> NormalizeLineTerminators(FlatStringReader& reader, | |
13030 IncrementalStringBuilder& builder) { | |
jwolfe
2016/07/18 18:33:10
Is the use of reference parameters here acceptable
Dan Ehrenberg
2016/07/18 18:52:31
We tend to use normal pointers in V8 instead.
| |
13031 for (int i = 0; i < reader.length(); i++) { | |
13032 Char c = reader.Get<Char>(i); | |
13033 if (c == '\r') { | |
13034 // normalize CR or CRLF | |
13035 builder.AppendCharacter('\n'); | |
13036 if (i + 1 < reader.length() && reader.Get<uint8_t>(i + 1) == '\n') { | |
13037 // also consume the LF in the CRLF | |
13038 i++; | |
13039 } | |
13040 } else { | |
13041 builder.Append<Char, Char>(c); | |
13042 } | |
13043 } | |
13044 return builder.Finish().ToHandleChecked(); | |
13045 } | |
13046 } // namespace | |
13047 | |
13048 Handle<Object> SharedFunctionInfo::GetSourceCodeHarmony() { | |
13049 Isolate* isolate = GetIsolate(); | |
13050 if (!HasSourceCode()) return isolate->factory()->undefined_value(); | |
13051 Handle<String> script_source(String::cast(Script::cast(script())->source())); | |
13052 int start_pos = function_token_position(); | |
13053 if (start_pos == kNoSourcePosition) start_pos = start_position(); | |
13054 Handle<String> function_source = isolate->factory()->NewSubString( | |
13055 script_source, start_pos, end_position()); | |
13056 // normalize line terminators | |
13057 FlatStringReader reader(isolate, function_source); | |
13058 // TODO(jwolfe): we know the upper bound on the build is reader.length(). how | |
13059 // to specify it? | |
13060 IncrementalStringBuilder builder(isolate); | |
13061 if (function_source->IsOneByteRepresentationUnderneath()) { | |
13062 return NormalizeLineTerminators<uint8_t>(reader, builder); | |
13063 } else { | |
13064 builder.ChangeEncoding(); | |
13065 return NormalizeLineTerminators<uc16>(reader, builder); | |
13066 } | |
13067 } | |
13024 | 13068 |
13025 bool SharedFunctionInfo::IsInlineable() { | 13069 bool SharedFunctionInfo::IsInlineable() { |
13026 // Check that the function has a script associated with it. | 13070 // Check that the function has a script associated with it. |
13027 if (!script()->IsScript()) return false; | 13071 if (!script()->IsScript()) return false; |
13028 return !optimization_disabled(); | 13072 return !optimization_disabled(); |
13029 } | 13073 } |
13030 | 13074 |
13031 | 13075 |
13032 int SharedFunctionInfo::SourceSize() { | 13076 int SharedFunctionInfo::SourceSize() { |
13033 return end_position() - start_position(); | 13077 return end_position() - start_position(); |
(...skipping 5901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18935 | 18979 |
18936 Object* data_obj = | 18980 Object* data_obj = |
18937 constructor->shared()->get_api_func_data()->access_check_info(); | 18981 constructor->shared()->get_api_func_data()->access_check_info(); |
18938 if (data_obj->IsUndefined(isolate)) return nullptr; | 18982 if (data_obj->IsUndefined(isolate)) return nullptr; |
18939 | 18983 |
18940 return AccessCheckInfo::cast(data_obj); | 18984 return AccessCheckInfo::cast(data_obj); |
18941 } | 18985 } |
18942 | 18986 |
18943 } // namespace internal | 18987 } // namespace internal |
18944 } // namespace v8 | 18988 } // namespace v8 |
OLD | NEW |