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 13240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13251 return isolate->factory()->NewSubString( | 13251 return isolate->factory()->NewSubString( |
13252 script_source, Handle<Smi>::cast(class_start_position)->value(), | 13252 script_source, Handle<Smi>::cast(class_start_position)->value(), |
13253 Handle<Smi>::cast(class_end_position)->value()); | 13253 Handle<Smi>::cast(class_end_position)->value()); |
13254 } | 13254 } |
13255 | 13255 |
13256 // Check if we have source code for the {function}. | 13256 // Check if we have source code for the {function}. |
13257 if (!shared_info->HasSourceCode()) { | 13257 if (!shared_info->HasSourceCode()) { |
13258 return NativeCodeFunctionSourceString(shared_info); | 13258 return NativeCodeFunctionSourceString(shared_info); |
13259 } | 13259 } |
13260 | 13260 |
13261 if (FLAG_harmony_function_tostring) { | |
13262 return Handle<String>::cast(shared_info->GetSourceCodeHarmony()); | |
13263 } | |
13264 | |
13261 IncrementalStringBuilder builder(isolate); | 13265 IncrementalStringBuilder builder(isolate); |
13262 FunctionKind kind = shared_info->kind(); | 13266 FunctionKind kind = shared_info->kind(); |
13263 if (!IsArrowFunction(kind)) { | 13267 if (!IsArrowFunction(kind)) { |
13264 if (IsConciseMethod(kind)) { | 13268 if (IsConciseMethod(kind)) { |
13265 if (IsGeneratorFunction(kind)) { | 13269 if (IsGeneratorFunction(kind)) { |
13266 builder.AppendCharacter('*'); | 13270 builder.AppendCharacter('*'); |
13267 } else if (IsAsyncFunction(kind)) { | 13271 } else if (IsAsyncFunction(kind)) { |
13268 builder.AppendCString("async "); | 13272 builder.AppendCString("async "); |
13269 } | 13273 } |
13270 } else { | 13274 } else { |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13666 } | 13670 } |
13667 | 13671 |
13668 | 13672 |
13669 Handle<Object> SharedFunctionInfo::GetSourceCode() { | 13673 Handle<Object> SharedFunctionInfo::GetSourceCode() { |
13670 if (!HasSourceCode()) return GetIsolate()->factory()->undefined_value(); | 13674 if (!HasSourceCode()) return GetIsolate()->factory()->undefined_value(); |
13671 Handle<String> source(String::cast(Script::cast(script())->source())); | 13675 Handle<String> source(String::cast(Script::cast(script())->source())); |
13672 return GetIsolate()->factory()->NewSubString( | 13676 return GetIsolate()->factory()->NewSubString( |
13673 source, start_position(), end_position()); | 13677 source, start_position(), end_position()); |
13674 } | 13678 } |
13675 | 13679 |
13680 namespace { | |
13681 template <typename Char> | |
13682 Handle<Object> NormalizeLineTerminators(FlatStringReader* reader, | |
13683 IncrementalStringBuilder* builder) { | |
13684 for (int i = 0; i < reader->length(); i++) { | |
13685 Char c = reader->Get<Char>(i); | |
13686 if (c == '\r') { | |
13687 // normalize CR or CRLF | |
13688 builder->AppendCharacter('\n'); | |
13689 if (i + 1 < reader->length() && reader->Get<Char>(i + 1) == '\n') { | |
13690 // also consume the LF in the CRLF | |
13691 i++; | |
13692 } | |
13693 } else { | |
13694 builder->Append<Char, Char>(c); | |
13695 } | |
13696 } | |
13697 return builder->Finish().ToHandleChecked(); | |
13698 } | |
13699 } // namespace | |
13700 | |
13701 Handle<Object> SharedFunctionInfo::GetSourceCodeHarmony() { | |
13702 Isolate* isolate = GetIsolate(); | |
13703 if (!HasSourceCode()) return isolate->factory()->undefined_value(); | |
13704 Handle<String> script_source(String::cast(Script::cast(script())->source())); | |
13705 int start_pos = function_token_position(); | |
13706 if (start_pos == kNoSourcePosition) start_pos = start_position(); | |
13707 Handle<String> function_source = isolate->factory()->NewSubString( | |
13708 script_source, start_pos, end_position()); | |
13709 // normalize line terminators | |
13710 FlatStringReader reader(isolate, function_source); | |
13711 // TODO(jwolfe): we know the upper bound on the build is reader.length(). how | |
13712 // to specify it? | |
jwolfe
2016/11/01 21:34:19
this is an optional optimization we may want to do
| |
13713 IncrementalStringBuilder builder(isolate); | |
13714 if (function_source->IsOneByteRepresentationUnderneath()) { | |
13715 return NormalizeLineTerminators<uint8_t>(&reader, &builder); | |
13716 } else { | |
13717 builder.ChangeEncoding(); | |
13718 return NormalizeLineTerminators<uc16>(&reader, &builder); | |
13719 } | |
13720 } | |
13676 | 13721 |
13677 bool SharedFunctionInfo::IsInlineable() { | 13722 bool SharedFunctionInfo::IsInlineable() { |
13678 // Check that the function has a script associated with it. | 13723 // Check that the function has a script associated with it. |
13679 if (!script()->IsScript()) return false; | 13724 if (!script()->IsScript()) return false; |
13680 return !optimization_disabled(); | 13725 return !optimization_disabled(); |
13681 } | 13726 } |
13682 | 13727 |
13683 | 13728 |
13684 int SharedFunctionInfo::SourceSize() { | 13729 int SharedFunctionInfo::SourceSize() { |
13685 return end_position() - start_position(); | 13730 return end_position() - start_position(); |
(...skipping 6532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20218 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) | 20263 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) |
20219 .Check(); | 20264 .Check(); |
20220 } | 20265 } |
20221 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); | 20266 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); |
20222 | 20267 |
20223 return ns; | 20268 return ns; |
20224 } | 20269 } |
20225 | 20270 |
20226 } // namespace internal | 20271 } // namespace internal |
20227 } // namespace v8 | 20272 } // namespace v8 |
OLD | NEW |