OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 2850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2861 | 2861 |
2862 static RawFunction* EvaluateHelper(const Class& cls, | 2862 static RawFunction* EvaluateHelper(const Class& cls, |
2863 const String& expr, | 2863 const String& expr, |
2864 const Array& param_names, | 2864 const Array& param_names, |
2865 bool is_static) { | 2865 bool is_static) { |
2866 const String& func_src = | 2866 const String& func_src = |
2867 String::Handle(BuildClosureSource(param_names, expr)); | 2867 String::Handle(BuildClosureSource(param_names, expr)); |
2868 Script& script = Script::Handle(); | 2868 Script& script = Script::Handle(); |
2869 script = Script::New(Symbols::EvalSourceUri(), | 2869 script = Script::New(Symbols::EvalSourceUri(), |
2870 func_src, | 2870 func_src, |
2871 RawScript::kSourceTag); | 2871 RawScript::kEvaluateTag); |
2872 // In order to tokenize the source, we need to get the key to mangle | 2872 // In order to tokenize the source, we need to get the key to mangle |
2873 // private names from the library from which the class originates. | 2873 // private names from the library from which the class originates. |
2874 const Library& lib = Library::Handle(cls.library()); | 2874 const Library& lib = Library::Handle(cls.library()); |
2875 ASSERT(!lib.IsNull()); | 2875 ASSERT(!lib.IsNull()); |
2876 const String& lib_key = String::Handle(lib.private_key()); | 2876 const String& lib_key = String::Handle(lib.private_key()); |
2877 script.Tokenize(lib_key); | 2877 script.Tokenize(lib_key); |
2878 | 2878 |
2879 const Function& func = Function::Handle( | 2879 const Function& func = Function::Handle( |
2880 Function::NewEvalFunction(cls, script, is_static)); | 2880 Function::NewEvalFunction(cls, script, is_static)); |
2881 func.set_result_type(Type::Handle(Type::DynamicType())); | 2881 func.set_result_type(Type::Handle(Type::DynamicType())); |
(...skipping 3403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6285 RawFunction::kRegularFunction, | 6285 RawFunction::kRegularFunction, |
6286 is_static, | 6286 is_static, |
6287 /* is_const = */ false, | 6287 /* is_const = */ false, |
6288 /* is_abstract = */ false, | 6288 /* is_abstract = */ false, |
6289 /* is_external = */ false, | 6289 /* is_external = */ false, |
6290 /* is_native = */ false, | 6290 /* is_native = */ false, |
6291 owner, | 6291 owner, |
6292 0)); | 6292 0)); |
6293 ASSERT(!script.IsNull()); | 6293 ASSERT(!script.IsNull()); |
6294 result.set_is_debuggable(false); | 6294 result.set_is_debuggable(false); |
6295 result.set_is_visible(false); | 6295 result.set_is_visible(true); |
6296 result.set_eval_script(script); | 6296 result.set_eval_script(script); |
6297 return result.raw(); | 6297 return result.raw(); |
6298 } | 6298 } |
6299 | 6299 |
6300 RawFunction* Function::ImplicitClosureFunction() const { | 6300 RawFunction* Function::ImplicitClosureFunction() const { |
6301 // Return the existing implicit closure function if any. | 6301 // Return the existing implicit closure function if any. |
6302 if (implicit_closure_function() != Function::null()) { | 6302 if (implicit_closure_function() != Function::null()) { |
6303 return implicit_closure_function(); | 6303 return implicit_closure_function(); |
6304 } | 6304 } |
6305 ASSERT(!IsSignatureFunction() && !IsClosureFunction()); | 6305 ASSERT(!IsSignatureFunction() && !IsClosureFunction()); |
(...skipping 2004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8310 const char* Script::GetKindAsCString() const { | 8310 const char* Script::GetKindAsCString() const { |
8311 switch (kind()) { | 8311 switch (kind()) { |
8312 case RawScript::kScriptTag: | 8312 case RawScript::kScriptTag: |
8313 return "script"; | 8313 return "script"; |
8314 case RawScript::kLibraryTag: | 8314 case RawScript::kLibraryTag: |
8315 return "library"; | 8315 return "library"; |
8316 case RawScript::kSourceTag: | 8316 case RawScript::kSourceTag: |
8317 return "source"; | 8317 return "source"; |
8318 case RawScript::kPatchTag: | 8318 case RawScript::kPatchTag: |
8319 return "patch"; | 8319 return "patch"; |
| 8320 case RawScript::kEvaluateTag: |
| 8321 return "evaluate"; |
8320 default: | 8322 default: |
8321 UNIMPLEMENTED(); | 8323 UNIMPLEMENTED(); |
8322 } | 8324 } |
8323 UNREACHABLE(); | 8325 UNREACHABLE(); |
8324 return NULL; | 8326 return NULL; |
8325 } | 8327 } |
8326 | 8328 |
8327 | 8329 |
8328 void Script::set_url(const String& value) const { | 8330 void Script::set_url(const String& value) const { |
8329 StorePointer(&raw_ptr()->url_, value.raw()); | 8331 StorePointer(&raw_ptr()->url_, value.raw()); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8585 | 8587 |
8586 // See also Dart_ScriptGetTokenInfo. | 8588 // See also Dart_ScriptGetTokenInfo. |
8587 void Script::PrintJSONImpl(JSONStream* stream, bool ref) const { | 8589 void Script::PrintJSONImpl(JSONStream* stream, bool ref) const { |
8588 JSONObject jsobj(stream); | 8590 JSONObject jsobj(stream); |
8589 AddCommonObjectProperties(&jsobj, "Script", ref); | 8591 AddCommonObjectProperties(&jsobj, "Script", ref); |
8590 const String& uri = String::Handle(url()); | 8592 const String& uri = String::Handle(url()); |
8591 ASSERT(!uri.IsNull()); | 8593 ASSERT(!uri.IsNull()); |
8592 const String& encoded_uri = String::Handle(String::EncodeIRI(uri)); | 8594 const String& encoded_uri = String::Handle(String::EncodeIRI(uri)); |
8593 ASSERT(!encoded_uri.IsNull()); | 8595 ASSERT(!encoded_uri.IsNull()); |
8594 const Library& lib = Library::Handle(FindLibrary()); | 8596 const Library& lib = Library::Handle(FindLibrary()); |
8595 // TODO(rmacnak): This can fail for eval scripts. Use a ring-id for those. | 8597 if (lib.IsNull()) { |
8596 intptr_t lib_index = (lib.IsNull()) ? -1 : lib.index(); | 8598 ASSERT(kind() == RawScript::kEvaluateTag); |
8597 jsobj.AddFixedServiceId("libraries/%" Pd "/scripts/%s", | 8599 jsobj.AddServiceId(*this); |
8598 lib_index, encoded_uri.ToCString()); | 8600 } else { |
| 8601 ASSERT(kind() != RawScript::kEvaluateTag); |
| 8602 jsobj.AddFixedServiceId("libraries/%" Pd "/scripts/%s", |
| 8603 lib.index(), encoded_uri.ToCString()); |
| 8604 } |
8599 jsobj.AddPropertyStr("uri", uri); | 8605 jsobj.AddPropertyStr("uri", uri); |
8600 jsobj.AddProperty("_kind", GetKindAsCString()); | 8606 jsobj.AddProperty("_kind", GetKindAsCString()); |
8601 if (ref) { | 8607 if (ref) { |
8602 return; | 8608 return; |
8603 } | 8609 } |
8604 jsobj.AddProperty("library", lib); | 8610 if (!lib.IsNull()) { |
| 8611 jsobj.AddProperty("library", lib); |
| 8612 } |
8605 const String& source = String::Handle(Source()); | 8613 const String& source = String::Handle(Source()); |
8606 jsobj.AddProperty("lineOffset", line_offset()); | 8614 jsobj.AddProperty("lineOffset", line_offset()); |
8607 jsobj.AddProperty("columnOffset", col_offset()); | 8615 jsobj.AddProperty("columnOffset", col_offset()); |
8608 jsobj.AddPropertyStr("source", source); | 8616 jsobj.AddPropertyStr("source", source); |
8609 | 8617 |
8610 // Print the line number table | 8618 // Print the line number table |
8611 { | 8619 { |
8612 JSONArray tokenPosTable(&jsobj, "tokenPosTable"); | 8620 JSONArray tokenPosTable(&jsobj, "tokenPosTable"); |
8613 | 8621 |
8614 const GrowableObjectArray& lineNumberArray = | 8622 const GrowableObjectArray& lineNumberArray = |
(...skipping 12345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20960 return tag_label.ToCString(); | 20968 return tag_label.ToCString(); |
20961 } | 20969 } |
20962 | 20970 |
20963 | 20971 |
20964 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20972 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
20965 Instance::PrintJSONImpl(stream, ref); | 20973 Instance::PrintJSONImpl(stream, ref); |
20966 } | 20974 } |
20967 | 20975 |
20968 | 20976 |
20969 } // namespace dart | 20977 } // namespace dart |
OLD | NEW |