Chromium Code Reviews| 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 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1801 | 1801 |
| 1802 | 1802 |
| 1803 void Class::AddFunction(const Function& function) const { | 1803 void Class::AddFunction(const Function& function) const { |
| 1804 const Array& arr = Array::Handle(functions()); | 1804 const Array& arr = Array::Handle(functions()); |
| 1805 const Array& new_arr = Array::Handle(Array::Grow(arr, arr.Length() + 1)); | 1805 const Array& new_arr = Array::Handle(Array::Grow(arr, arr.Length() + 1)); |
| 1806 new_arr.SetAt(arr.Length(), function); | 1806 new_arr.SetAt(arr.Length(), function); |
| 1807 SetFunctions(new_arr); | 1807 SetFunctions(new_arr); |
| 1808 } | 1808 } |
| 1809 | 1809 |
| 1810 | 1810 |
| 1811 intptr_t Class::FindFunctionIndex(const Function& needle) const { | |
| 1812 Isolate* isolate = Isolate::Current(); | |
| 1813 if (EnsureIsFinalized(isolate) != Error::null()) { | |
| 1814 return -1; | |
| 1815 } | |
| 1816 ReusableHandleScope reused_handles(isolate); | |
| 1817 Array& funcs = reused_handles.ArrayHandle(); | |
| 1818 funcs ^= functions(); | |
| 1819 ASSERT(!funcs.IsNull()); | |
| 1820 Function& function = reused_handles.FunctionHandle(); | |
| 1821 String& function_name = reused_handles.StringHandle(); | |
| 1822 String& needle_name = String::Handle(); | |
|
turnidge
2013/12/19 20:39:29
String::Handle(isolate) maybe? Avoids a call to I
Cutch
2013/12/19 21:53:58
Done.
| |
| 1823 needle_name ^= needle.name(); | |
| 1824 const intptr_t len = funcs.Length(); | |
| 1825 for (intptr_t i = 0; i < len; i++) { | |
| 1826 function ^= funcs.At(i); | |
| 1827 function_name ^= function.name(); | |
| 1828 if (function_name.Equals(needle_name)) { | |
| 1829 return i; | |
| 1830 } | |
| 1831 } | |
| 1832 // No function found. | |
| 1833 return -1; | |
| 1834 } | |
| 1835 | |
| 1836 | |
| 1811 void Class::AddClosureFunction(const Function& function) const { | 1837 void Class::AddClosureFunction(const Function& function) const { |
| 1812 GrowableObjectArray& closures = | 1838 GrowableObjectArray& closures = |
| 1813 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); | 1839 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); |
| 1814 if (closures.IsNull()) { | 1840 if (closures.IsNull()) { |
| 1815 closures = GrowableObjectArray::New(4); | 1841 closures = GrowableObjectArray::New(4); |
| 1816 StorePointer(&raw_ptr()->closure_functions_, closures.raw()); | 1842 StorePointer(&raw_ptr()->closure_functions_, closures.raw()); |
| 1817 } | 1843 } |
| 1818 ASSERT(function.IsNonImplicitClosureFunction()); | 1844 ASSERT(function.IsNonImplicitClosureFunction()); |
| 1819 closures.Add(function); | 1845 closures.Add(function); |
| 1820 } | 1846 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1841 best_fit_token_pos = closure.token_pos(); | 1867 best_fit_token_pos = closure.token_pos(); |
| 1842 } | 1868 } |
| 1843 } | 1869 } |
| 1844 closure = Function::null(); | 1870 closure = Function::null(); |
| 1845 if (best_fit_index >= 0) { | 1871 if (best_fit_index >= 0) { |
| 1846 closure ^= closures.At(best_fit_index); | 1872 closure ^= closures.At(best_fit_index); |
| 1847 } | 1873 } |
| 1848 return closure.raw(); | 1874 return closure.raw(); |
| 1849 } | 1875 } |
| 1850 | 1876 |
| 1877 intptr_t Class::FindClosureIndex(intptr_t token_pos) const { | |
| 1878 if (raw_ptr()->closure_functions_ == GrowableObjectArray::null()) { | |
| 1879 return -1; | |
| 1880 } | |
|
turnidge
2013/12/19 20:39:29
Do you want to use the ReusableHandleScope here fo
Cutch
2013/12/19 21:53:58
Done.
| |
| 1881 const GrowableObjectArray& closures = | |
| 1882 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); | |
| 1883 Function& closure = Function::Handle(); | |
| 1884 intptr_t num_closures = closures.Length(); | |
| 1885 intptr_t best_fit_token_pos = -1; | |
| 1886 intptr_t best_fit_index = -1; | |
| 1887 for (intptr_t i = 0; i < num_closures; i++) { | |
| 1888 closure ^= closures.At(i); | |
| 1889 ASSERT(!closure.IsNull()); | |
| 1890 if ((closure.token_pos() <= token_pos) && | |
| 1891 (token_pos <= closure.end_token_pos()) && | |
| 1892 (best_fit_token_pos < closure.token_pos())) { | |
| 1893 best_fit_index = i; | |
| 1894 best_fit_token_pos = closure.token_pos(); | |
| 1895 } | |
| 1896 } | |
| 1897 return best_fit_index; | |
| 1898 } | |
| 1899 | |
| 1851 | 1900 |
| 1852 void Class::set_signature_function(const Function& value) const { | 1901 void Class::set_signature_function(const Function& value) const { |
| 1853 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); | 1902 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); |
| 1854 StorePointer(&raw_ptr()->signature_function_, value.raw()); | 1903 StorePointer(&raw_ptr()->signature_function_, value.raw()); |
| 1855 } | 1904 } |
| 1856 | 1905 |
| 1857 | 1906 |
| 1858 void Class::set_state_bits(intptr_t bits) const { | 1907 void Class::set_state_bits(intptr_t bits) const { |
| 1859 raw_ptr()->state_bits_ = static_cast<uint16_t>(bits); | 1908 raw_ptr()->state_bits_ = static_cast<uint16_t>(bits); |
| 1860 } | 1909 } |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2392 for (intptr_t i = 0; i < len; i++) { | 2441 for (intptr_t i = 0; i < len; i++) { |
| 2393 field ^= value.At(i); | 2442 field ^= value.At(i); |
| 2394 ASSERT(field.owner() == raw()); | 2443 ASSERT(field.owner() == raw()); |
| 2395 } | 2444 } |
| 2396 #endif | 2445 #endif |
| 2397 // The value of static fields is already initialized to null. | 2446 // The value of static fields is already initialized to null. |
| 2398 StorePointer(&raw_ptr()->fields_, value.raw()); | 2447 StorePointer(&raw_ptr()->fields_, value.raw()); |
| 2399 } | 2448 } |
| 2400 | 2449 |
| 2401 | 2450 |
| 2451 intptr_t Class::FindFieldIndex(const Field& needle) const { | |
| 2452 Isolate* isolate = Isolate::Current(); | |
| 2453 if (EnsureIsFinalized(isolate) != Error::null()) { | |
| 2454 return -1; | |
| 2455 } | |
| 2456 ReusableHandleScope reused_handles(isolate); | |
| 2457 Array& fields_array = reused_handles.ArrayHandle(); | |
| 2458 fields_array ^= fields(); | |
| 2459 ASSERT(!fields_array.IsNull()); | |
| 2460 Field& field = reused_handles.FieldHandle(); | |
| 2461 String& field_name = reused_handles.StringHandle(); | |
| 2462 String& needle_name = String::Handle(); | |
|
turnidge
2013/12/19 20:39:29
String::Handle(isolate)
Do we run into this a lot
Cutch
2013/12/19 21:53:58
Depends on user activity. We hit this whenever we
turnidge
2013/12/20 17:44:45
I meant do we run into needing two String handles
| |
| 2463 needle_name ^= needle.name(); | |
| 2464 const intptr_t len = fields_array.Length(); | |
| 2465 for (intptr_t i = 0; i < len; i++) { | |
| 2466 field ^= fields_array.At(i); | |
| 2467 field_name ^= field.name(); | |
| 2468 if (field_name.Equals(needle_name)) { | |
| 2469 return i; | |
| 2470 } | |
| 2471 } | |
| 2472 // No field found found. | |
| 2473 return -1; | |
| 2474 } | |
| 2475 | |
| 2476 | |
| 2402 template <class FakeInstance> | 2477 template <class FakeInstance> |
| 2403 RawClass* Class::New(intptr_t index) { | 2478 RawClass* Class::New(intptr_t index) { |
| 2404 ASSERT(Object::class_class() != Class::null()); | 2479 ASSERT(Object::class_class() != Class::null()); |
| 2405 Class& result = Class::Handle(); | 2480 Class& result = Class::Handle(); |
| 2406 { | 2481 { |
| 2407 RawObject* raw = Object::Allocate(Class::kClassId, | 2482 RawObject* raw = Object::Allocate(Class::kClassId, |
| 2408 Class::InstanceSize(), | 2483 Class::InstanceSize(), |
| 2409 Heap::kOld); | 2484 Heap::kOld); |
| 2410 NoGCScope no_gc; | 2485 NoGCScope no_gc; |
| 2411 result ^= raw; | 2486 result ^= raw; |
| (...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3241 void Class::PrintToJSONStream(JSONStream* stream, bool ref) const { | 3316 void Class::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 3242 JSONObject jsobj(stream); | 3317 JSONObject jsobj(stream); |
| 3243 if ((raw() == Class::null()) || (id() == kFreeListElement)) { | 3318 if ((raw() == Class::null()) || (id() == kFreeListElement)) { |
| 3244 jsobj.AddProperty("type", "Null"); | 3319 jsobj.AddProperty("type", "Null"); |
| 3245 return; | 3320 return; |
| 3246 } | 3321 } |
| 3247 const char* internal_class_name = String::Handle(Name()).ToCString(); | 3322 const char* internal_class_name = String::Handle(Name()).ToCString(); |
| 3248 const char* user_visible_class_name = | 3323 const char* user_visible_class_name = |
| 3249 String::Handle(UserVisibleName()).ToCString(); | 3324 String::Handle(UserVisibleName()).ToCString(); |
| 3250 jsobj.AddProperty("type", JSONType(ref)); | 3325 jsobj.AddProperty("type", JSONType(ref)); |
| 3251 jsobj.AddProperty("id", id()); | 3326 jsobj.AddPropertyF("id", "classes/%" Pd "", id()); |
| 3252 jsobj.AddProperty("name", internal_class_name); | 3327 jsobj.AddProperty("name", internal_class_name); |
| 3253 jsobj.AddProperty("user_name", user_visible_class_name); | 3328 jsobj.AddProperty("user_name", user_visible_class_name); |
| 3254 if (!ref) { | 3329 if (!ref) { |
| 3255 const Error& err = Error::Handle(EnsureIsFinalized(Isolate::Current())); | 3330 const Error& err = Error::Handle(EnsureIsFinalized(Isolate::Current())); |
| 3256 if (!err.IsNull()) { | 3331 if (!err.IsNull()) { |
| 3257 jsobj.AddProperty("error", err); | 3332 jsobj.AddProperty("error", err); |
| 3258 } | 3333 } |
| 3259 jsobj.AddProperty("implemented", is_implemented()); | 3334 jsobj.AddProperty("implemented", is_implemented()); |
| 3260 jsobj.AddProperty("abstract", is_abstract()); | 3335 jsobj.AddProperty("abstract", is_abstract()); |
| 3261 jsobj.AddProperty("patch", is_patch()); | 3336 jsobj.AddProperty("patch", is_patch()); |
| (...skipping 2350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5612 OS::SNPrint(chars, len, kFormat, function_name, | 5687 OS::SNPrint(chars, len, kFormat, function_name, |
| 5613 static_str, abstract_str, kind_str, const_str); | 5688 static_str, abstract_str, kind_str, const_str); |
| 5614 return chars; | 5689 return chars; |
| 5615 } | 5690 } |
| 5616 | 5691 |
| 5617 | 5692 |
| 5618 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const { | 5693 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 5619 const char* internal_function_name = String::Handle(name()).ToCString(); | 5694 const char* internal_function_name = String::Handle(name()).ToCString(); |
| 5620 const char* function_name = | 5695 const char* function_name = |
| 5621 String::Handle(QualifiedUserVisibleName()).ToCString(); | 5696 String::Handle(QualifiedUserVisibleName()).ToCString(); |
| 5622 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 5697 Class& cls = Class::Handle(Owner()); |
| 5623 intptr_t id = ring->GetIdForObject(raw()); | 5698 Error& err = Error::Handle(); |
| 5699 err ^= cls.EnsureIsFinalized(Isolate::Current()); | |
| 5700 ASSERT(err.IsNull()); | |
| 5701 Function& func = Function::Handle(raw()); | |
|
turnidge
2013/12/19 20:39:29
Instead of:
Function::Handle(raw())
Can we get a
| |
| 5702 intptr_t id = cls.FindFunctionIndex(func); | |
| 5703 bool closure = false; | |
| 5704 if (id == -1) { | |
| 5705 closure = true; | |
|
turnidge
2013/12/19 20:39:29
There is an IsClosureFunction predicate in Functio
Cutch
2013/12/19 21:53:58
Possibly, let me test.
| |
| 5706 id = cls.FindClosureIndex(token_pos()); | |
| 5707 } | |
| 5708 ASSERT(id >= 0); | |
| 5709 intptr_t cid = cls.id(); | |
| 5624 JSONObject jsobj(stream); | 5710 JSONObject jsobj(stream); |
| 5625 jsobj.AddProperty("type", JSONType(ref)); | 5711 jsobj.AddProperty("type", JSONType(ref)); |
| 5626 jsobj.AddProperty("id", id); | 5712 if (closure) { |
| 5713 jsobj.AddPropertyF("id", "classes/%" Pd "/closures/%" Pd "", cid, id); | |
|
turnidge
2013/12/19 20:39:29
For thought: I'm wondering if these format strings
Cutch
2013/12/19 21:53:58
Agreed.
| |
| 5714 } else { | |
| 5715 jsobj.AddPropertyF("id", "classes/%" Pd "/functions/%" Pd "", cid, id); | |
| 5716 } | |
| 5627 jsobj.AddProperty("name", internal_function_name); | 5717 jsobj.AddProperty("name", internal_function_name); |
| 5628 jsobj.AddProperty("user_name", function_name); | 5718 jsobj.AddProperty("user_name", function_name); |
| 5629 if (ref) return; | 5719 if (ref) return; |
| 5630 jsobj.AddProperty("is_static", is_static()); | 5720 jsobj.AddProperty("is_static", is_static()); |
| 5631 jsobj.AddProperty("is_const", is_const()); | 5721 jsobj.AddProperty("is_const", is_const()); |
| 5632 jsobj.AddProperty("is_optimizable", is_optimizable()); | 5722 jsobj.AddProperty("is_optimizable", is_optimizable()); |
| 5633 jsobj.AddProperty("is_inlinable", IsInlineable()); | 5723 jsobj.AddProperty("is_inlinable", IsInlineable()); |
| 5634 const char* kind_string = NULL; | 5724 const char* kind_string = NULL; |
| 5635 switch (kind()) { | 5725 switch (kind()) { |
| 5636 case RawFunction::kRegularFunction: | 5726 case RawFunction::kRegularFunction: |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5945 PrintToJSONStreamWithInstance(stream, Object::null_instance(), ref); | 6035 PrintToJSONStreamWithInstance(stream, Object::null_instance(), ref); |
| 5946 } | 6036 } |
| 5947 | 6037 |
| 5948 | 6038 |
| 5949 void Field::PrintToJSONStreamWithInstance(JSONStream* stream, | 6039 void Field::PrintToJSONStreamWithInstance(JSONStream* stream, |
| 5950 const Instance& instance, | 6040 const Instance& instance, |
| 5951 bool ref) const { | 6041 bool ref) const { |
| 5952 JSONObject jsobj(stream); | 6042 JSONObject jsobj(stream); |
| 5953 const char* internal_field_name = String::Handle(name()).ToCString(); | 6043 const char* internal_field_name = String::Handle(name()).ToCString(); |
| 5954 const char* field_name = String::Handle(UserVisibleName()).ToCString(); | 6044 const char* field_name = String::Handle(UserVisibleName()).ToCString(); |
| 5955 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 6045 Class& cls = Class::Handle(owner()); |
| 5956 intptr_t id = ring->GetIdForObject(raw()); | 6046 intptr_t id = cls.FindFieldIndex(Field::Handle(raw())); |
|
turnidge
2013/12/19 20:39:29
*this
Cutch
2013/12/19 21:53:58
Done.
| |
| 6047 ASSERT(id >= 0); | |
| 6048 intptr_t cid = cls.id(); | |
| 5957 jsobj.AddProperty("type", JSONType(ref)); | 6049 jsobj.AddProperty("type", JSONType(ref)); |
| 5958 jsobj.AddProperty("id", id); | 6050 jsobj.AddPropertyF("id", "classes/%" Pd "/fields/%" Pd "", cid, id); |
| 5959 jsobj.AddProperty("name", internal_field_name); | 6051 jsobj.AddProperty("name", internal_field_name); |
| 5960 jsobj.AddProperty("user_name", field_name); | 6052 jsobj.AddProperty("user_name", field_name); |
| 5961 if (is_static()) { | 6053 if (is_static()) { |
| 5962 const Object& valueObj = Object::Handle(value()); | 6054 const Object& valueObj = Object::Handle(value()); |
| 5963 jsobj.AddProperty("value", valueObj); | 6055 jsobj.AddProperty("value", valueObj); |
| 5964 } else if (!instance.IsNull()) { | 6056 } else if (!instance.IsNull()) { |
| 5965 const Object& valueObj = Object::Handle(instance.GetField(*this)); | 6057 const Object& valueObj = Object::Handle(instance.GetField(*this)); |
| 5966 jsobj.AddProperty("value", valueObj); | 6058 jsobj.AddProperty("value", valueObj); |
| 5967 } | 6059 } |
| 5968 Class& cls = Class::Handle(owner()); | 6060 |
| 5969 jsobj.AddProperty("owner", cls); | 6061 jsobj.AddProperty("owner", cls); |
| 5970 AbstractType& declared_type = AbstractType::Handle(type()); | 6062 AbstractType& declared_type = AbstractType::Handle(type()); |
| 5971 cls = declared_type.type_class(); | 6063 cls = declared_type.type_class(); |
| 5972 jsobj.AddProperty("declared_type", cls); | 6064 jsobj.AddProperty("declared_type", cls); |
| 5973 jsobj.AddProperty("static", is_static()); | 6065 jsobj.AddProperty("static", is_static()); |
| 5974 jsobj.AddProperty("final", is_final()); | 6066 jsobj.AddProperty("final", is_final()); |
| 5975 jsobj.AddProperty("const", is_const()); | 6067 jsobj.AddProperty("const", is_const()); |
| 5976 if (ref) { | 6068 if (ref) { |
| 5977 return; | 6069 return; |
| 5978 } | 6070 } |
| (...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7112 } | 7204 } |
| 7113 | 7205 |
| 7114 | 7206 |
| 7115 const char* Script::ToCString() const { | 7207 const char* Script::ToCString() const { |
| 7116 return "Script"; | 7208 return "Script"; |
| 7117 } | 7209 } |
| 7118 | 7210 |
| 7119 | 7211 |
| 7120 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const { | 7212 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 7121 JSONObject jsobj(stream); | 7213 JSONObject jsobj(stream); |
| 7122 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | |
| 7123 intptr_t id = ring->GetIdForObject(raw()); | |
| 7124 jsobj.AddProperty("type", JSONType(ref)); | 7214 jsobj.AddProperty("type", JSONType(ref)); |
| 7125 jsobj.AddProperty("id", id); | |
| 7126 const String& name = String::Handle(url()); | 7215 const String& name = String::Handle(url()); |
| 7216 ASSERT(!name.IsNull()); | |
| 7217 const String& encoded_url = String::Handle(String::EncodeURI(name)); | |
| 7218 ASSERT(!encoded_url.IsNull()); | |
| 7219 jsobj.AddPropertyF("id", "scripts/%s", encoded_url.ToCString()); | |
| 7127 jsobj.AddProperty("name", name.ToCString()); | 7220 jsobj.AddProperty("name", name.ToCString()); |
| 7128 jsobj.AddProperty("kind", GetKindAsCString()); | 7221 jsobj.AddProperty("kind", GetKindAsCString()); |
| 7129 if (ref) { | 7222 if (ref) { |
| 7130 return; | 7223 return; |
| 7131 } | 7224 } |
| 7132 const String& source = String::Handle(Source()); | 7225 const String& source = String::Handle(Source()); |
| 7133 jsobj.AddProperty("source", source.ToCString()); | 7226 jsobj.AddProperty("source", source.ToCString()); |
| 7134 } | 7227 } |
| 7135 | 7228 |
| 7136 | 7229 |
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8186 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; | 8279 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; |
| 8187 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 8280 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 8188 OS::SNPrint(chars, len, kFormat, name.ToCString()); | 8281 OS::SNPrint(chars, len, kFormat, name.ToCString()); |
| 8189 return chars; | 8282 return chars; |
| 8190 } | 8283 } |
| 8191 | 8284 |
| 8192 | 8285 |
| 8193 void Library::PrintToJSONStream(JSONStream* stream, bool ref) const { | 8286 void Library::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 8194 const char* library_name = String::Handle(name()).ToCString(); | 8287 const char* library_name = String::Handle(name()).ToCString(); |
| 8195 const char* library_url = String::Handle(url()).ToCString(); | 8288 const char* library_url = String::Handle(url()).ToCString(); |
| 8196 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 8289 intptr_t id = index(); |
| 8197 intptr_t id = ring->GetIdForObject(raw()); | 8290 ASSERT(id >= 0); |
| 8198 JSONObject jsobj(stream); | 8291 JSONObject jsobj(stream); |
| 8199 jsobj.AddProperty("type", JSONType(ref)); | 8292 jsobj.AddProperty("type", JSONType(ref)); |
| 8200 jsobj.AddProperty("id", id); | 8293 jsobj.AddPropertyF("id", "libraries/%" Pd "", id); |
| 8201 jsobj.AddProperty("name", library_name); | 8294 jsobj.AddProperty("name", library_name); |
| 8202 jsobj.AddProperty("url", library_url); | 8295 jsobj.AddProperty("user_name", library_url); |
| 8203 if (ref) return; | 8296 if (ref) return; |
| 8204 { | 8297 { |
| 8205 JSONArray jsarr(&jsobj, "classes"); | 8298 JSONArray jsarr(&jsobj, "classes"); |
| 8206 ClassDictionaryIterator class_iter(*this); | 8299 ClassDictionaryIterator class_iter(*this); |
| 8207 Class& klass = Class::Handle(); | 8300 Class& klass = Class::Handle(); |
| 8208 while (class_iter.HasNext()) { | 8301 while (class_iter.HasNext()) { |
| 8209 klass = class_iter.GetNextClass(); | 8302 klass = class_iter.GetNextClass(); |
| 8210 if (!klass.IsCanonicalSignatureClass() && | 8303 if (!klass.IsCanonicalSignatureClass() && |
| 8211 !klass.IsAnonymousMixinApplication()) { | 8304 !klass.IsAnonymousMixinApplication()) { |
| 8212 jsarr.AddValue(klass); | 8305 jsarr.AddValue(klass); |
| (...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9762 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 9855 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 9763 OS::SNPrint(chars, len, kFormat, EntryPoint()); | 9856 OS::SNPrint(chars, len, kFormat, EntryPoint()); |
| 9764 return chars; | 9857 return chars; |
| 9765 } | 9858 } |
| 9766 | 9859 |
| 9767 | 9860 |
| 9768 void Code::PrintToJSONStream(JSONStream* stream, bool ref) const { | 9861 void Code::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 9769 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 9862 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
| 9770 intptr_t id = ring->GetIdForObject(raw()); | 9863 intptr_t id = ring->GetIdForObject(raw()); |
| 9771 JSONObject jsobj(stream); | 9864 JSONObject jsobj(stream); |
| 9865 jsobj.AddProperty("type", JSONType(ref)); | |
| 9866 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | |
| 9867 if (is_optimized()) { | |
| 9868 jsobj.AddProperty("name", "optimized code"); | |
| 9869 jsobj.AddProperty("user_name", "optimized code"); | |
| 9870 } else { | |
| 9871 jsobj.AddProperty("name", "regular code"); | |
| 9872 jsobj.AddProperty("user_name", "regular code"); | |
|
turnidge
2013/12/19 20:39:29
Too bad we can't get a nice name here. I wonder..
Cutch
2013/12/19 21:53:58
Done.
| |
| 9873 } | |
| 9772 if (ref) { | 9874 if (ref) { |
| 9773 jsobj.AddProperty("type", "@Code"); | |
| 9774 jsobj.AddProperty("id", id); | |
| 9775 return; | 9875 return; |
| 9776 } | 9876 } |
| 9777 jsobj.AddProperty("type", "Code"); | |
| 9778 jsobj.AddProperty("id", id); | |
| 9779 jsobj.AddProperty("is_optimized", is_optimized()); | 9877 jsobj.AddProperty("is_optimized", is_optimized()); |
| 9780 jsobj.AddProperty("is_alive", is_alive()); | 9878 jsobj.AddProperty("is_alive", is_alive()); |
| 9781 jsobj.AddProperty("function", Object::Handle(function())); | 9879 jsobj.AddProperty("function", Object::Handle(function())); |
| 9782 JSONArray jsarr(&jsobj, "disassembly"); | 9880 JSONArray jsarr(&jsobj, "disassembly"); |
| 9783 DisassembleToJSONStream formatter(jsarr); | 9881 DisassembleToJSONStream formatter(jsarr); |
| 9784 const Instructions& instr = Instructions::Handle(instructions()); | 9882 const Instructions& instr = Instructions::Handle(instructions()); |
| 9785 uword start = instr.EntryPoint(); | 9883 uword start = instr.EntryPoint(); |
| 9786 Disassembler::Disassemble(start, start + instr.size(), &formatter, | 9884 Disassembler::Disassemble(start, start + instr.size(), &formatter, |
| 9787 comments()); | 9885 comments()); |
| 9788 } | 9886 } |
| (...skipping 1681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11470 } | 11568 } |
| 11471 } | 11569 } |
| 11472 | 11570 |
| 11473 | 11571 |
| 11474 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const { | 11572 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 11475 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 11573 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
| 11476 intptr_t id = ring->GetIdForObject(raw()); | 11574 intptr_t id = ring->GetIdForObject(raw()); |
| 11477 | 11575 |
| 11478 JSONObject jsobj(stream); | 11576 JSONObject jsobj(stream); |
| 11479 jsobj.AddProperty("type", JSONType(ref)); | 11577 jsobj.AddProperty("type", JSONType(ref)); |
| 11480 jsobj.AddProperty("id", id); | 11578 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
| 11481 | 11579 |
| 11482 Class& cls = Class::Handle(this->clazz()); | 11580 Class& cls = Class::Handle(this->clazz()); |
| 11483 jsobj.AddProperty("class", cls); | 11581 jsobj.AddProperty("class", cls); |
| 11484 | 11582 |
| 11485 // Set the "preview" property for this instance. | 11583 // Set the "preview" property for this instance. |
| 11486 if (IsNull()) { | 11584 if (IsNull()) { |
| 11487 jsobj.AddProperty("preview", "null"); | 11585 jsobj.AddProperty("preview", "null"); |
| 11488 } else { | 11586 } else { |
| 11489 jsobj.AddProperty("preview", ToUserCString(40)); | 11587 jsobj.AddProperty("preview", ToUserCString(40)); |
| 11490 } | 11588 } |
| (...skipping 2837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14328 } | 14426 } |
| 14329 ASSERT(str.IsExternalTwoByteString()); | 14427 ASSERT(str.IsExternalTwoByteString()); |
| 14330 // If EscapeSpecialCharacters is frequently called on external two byte | 14428 // If EscapeSpecialCharacters is frequently called on external two byte |
| 14331 // strings, we should implement it directly on ExternalTwoByteString rather | 14429 // strings, we should implement it directly on ExternalTwoByteString rather |
| 14332 // than first converting to a TwoByteString. | 14430 // than first converting to a TwoByteString. |
| 14333 return TwoByteString::EscapeSpecialCharacters( | 14431 return TwoByteString::EscapeSpecialCharacters( |
| 14334 String::Handle(TwoByteString::New(str, Heap::kNew))); | 14432 String::Handle(TwoByteString::New(str, Heap::kNew))); |
| 14335 } | 14433 } |
| 14336 | 14434 |
| 14337 | 14435 |
| 14436 RawString* String::EncodeURI(const String& str) { | |
| 14437 if (str.IsOneByteString()) { | |
| 14438 return OneByteString::EncodeURI(str); | |
| 14439 } | |
| 14440 if (str.IsExternalOneByteString()) { | |
| 14441 return ExternalOneByteString::EncodeURI(str); | |
| 14442 } | |
| 14443 return String::null(); | |
|
turnidge
2013/12/19 20:39:29
Is this case UNREACHABLE or UNIMPLEMENTED?
Cutch
2013/12/19 21:53:58
Added UNREACHABLE();
| |
| 14444 } | |
| 14445 | |
| 14446 | |
| 14447 RawString* String::DecodeURI(const String& str) { | |
| 14448 if (str.IsOneByteString()) { | |
| 14449 return OneByteString::DecodeURI(str); | |
| 14450 } | |
| 14451 if (str.IsExternalOneByteString()) { | |
| 14452 return ExternalOneByteString::DecodeURI(str); | |
| 14453 } | |
| 14454 return String::null(); | |
| 14455 } | |
| 14456 | |
| 14457 | |
| 14338 RawString* String::NewFormatted(const char* format, ...) { | 14458 RawString* String::NewFormatted(const char* format, ...) { |
| 14339 va_list args; | 14459 va_list args; |
| 14340 va_start(args, format); | 14460 va_start(args, format); |
| 14341 RawString* result = NewFormattedV(format, args); | 14461 RawString* result = NewFormattedV(format, args); |
| 14342 NoGCScope no_gc; | 14462 NoGCScope no_gc; |
| 14343 va_end(args); | 14463 va_end(args); |
| 14344 return result; | 14464 return result; |
| 14345 } | 14465 } |
| 14346 | 14466 |
| 14347 | 14467 |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14885 *(OneByteString::CharAddr(dststr, index)) = *CharAddr(str, i); | 15005 *(OneByteString::CharAddr(dststr, index)) = *CharAddr(str, i); |
| 14886 index += 1; | 15006 index += 1; |
| 14887 } | 15007 } |
| 14888 } | 15008 } |
| 14889 return OneByteString::raw(dststr); | 15009 return OneByteString::raw(dststr); |
| 14890 } | 15010 } |
| 14891 return OneByteString::raw(Symbols::Empty()); | 15011 return OneByteString::raw(Symbols::Empty()); |
| 14892 } | 15012 } |
| 14893 | 15013 |
| 14894 | 15014 |
| 15015 static bool IsPercent(int32_t c) { | |
| 15016 return c == '%'; | |
| 15017 } | |
| 15018 | |
| 15019 static bool IsURISafeCharacter(int32_t c) { | |
| 15020 if ((c >= '0') && (c <= '9')) { | |
| 15021 return true; | |
| 15022 } | |
| 15023 if ((c >= 'a') && (c <= 'z')) { | |
| 15024 return true; | |
| 15025 } | |
| 15026 if ((c >= 'A') && (c <= 'Z')) { | |
| 15027 return true; | |
| 15028 } | |
| 15029 return (c == '-') || (c == '_') || (c == '.') || (c == '~'); | |
| 15030 } | |
| 15031 | |
| 15032 | |
| 15033 static int32_t GetHexCharacter(int32_t c) { | |
| 15034 ASSERT(c >= 0); | |
| 15035 ASSERT(c < 16); | |
| 15036 const char* hex = "0123456789ABCDEF"; | |
| 15037 return hex[c]; | |
| 15038 } | |
| 15039 | |
| 15040 | |
| 15041 static int32_t GetHexValue(int32_t c) { | |
| 15042 if (c >= '0' && c <= '9') { | |
| 15043 return c - '0'; | |
| 15044 } | |
| 15045 if (c >= 'A' && c <= 'F') { | |
| 15046 return c - 'A' + 10; | |
| 15047 } | |
| 15048 UNREACHABLE(); | |
| 15049 return 0; | |
| 15050 } | |
| 15051 | |
| 15052 | |
| 15053 static int32_t MergeHexCharacters(int32_t c1, int32_t c2) { | |
| 15054 return GetHexValue(c1) << 4 | GetHexValue(c2); | |
| 15055 } | |
| 15056 | |
| 15057 | |
| 15058 RawOneByteString* OneByteString::EncodeURI(const String& str) { | |
| 15059 intptr_t len = str.Length(); | |
| 15060 if (len > 0) { | |
| 15061 intptr_t num_escapes = 0; | |
| 15062 for (intptr_t i = 0; i < len; i++) { | |
| 15063 if (!IsURISafeCharacter(*CharAddr(str, i))) { | |
| 15064 num_escapes += 2; | |
| 15065 } | |
| 15066 } | |
| 15067 const String& dststr = String::Handle( | |
| 15068 OneByteString::New(len + num_escapes, Heap::kNew)); | |
| 15069 intptr_t index = 0; | |
| 15070 for (intptr_t i = 0; i < len; i++) { | |
| 15071 if (!IsURISafeCharacter(*CharAddr(str, i))) { | |
| 15072 *(CharAddr(dststr, index)) = '%'; | |
| 15073 int32_t ch = *CharAddr(str, i); | |
| 15074 *(CharAddr(dststr, index + 1)) = GetHexCharacter(ch >> 4); | |
| 15075 *(CharAddr(dststr, index + 2)) = GetHexCharacter(ch & 0xF); | |
| 15076 index += 3; | |
| 15077 } else { | |
| 15078 *(CharAddr(dststr, index)) = *CharAddr(str, i); | |
| 15079 index += 1; | |
| 15080 } | |
| 15081 } | |
| 15082 return OneByteString::raw(dststr); | |
| 15083 } | |
| 15084 return OneByteString::raw(Symbols::Empty()); | |
| 15085 } | |
| 15086 | |
| 15087 | |
| 15088 RawOneByteString* ExternalOneByteString::EncodeURI(const String& str) { | |
| 15089 intptr_t len = str.Length(); | |
| 15090 if (len > 0) { | |
| 15091 intptr_t num_escapes = 0; | |
| 15092 for (intptr_t i = 0; i < len; i++) { | |
| 15093 if (!IsURISafeCharacter(*CharAddr(str, i))) { | |
| 15094 num_escapes += 2; | |
| 15095 } | |
| 15096 } | |
| 15097 const String& dststr = String::Handle( | |
| 15098 OneByteString::New(len + num_escapes, Heap::kNew)); | |
| 15099 intptr_t index = 0; | |
| 15100 for (intptr_t i = 0; i < len; i++) { | |
| 15101 if (!IsURISafeCharacter(*CharAddr(str, i))) { | |
| 15102 *(OneByteString::CharAddr(dststr, index)) = '%'; | |
| 15103 int32_t ch = *CharAddr(str, i); | |
| 15104 *(OneByteString::CharAddr(dststr, index + 1)) = | |
| 15105 GetHexCharacter(ch >> 4); | |
| 15106 *(OneByteString::CharAddr(dststr, index + 2)) = | |
| 15107 GetHexCharacter(ch & 0xF); | |
| 15108 index += 3; | |
| 15109 } else { | |
| 15110 *(OneByteString::CharAddr(dststr, index)) = *CharAddr(str, i); | |
| 15111 index += 1; | |
| 15112 } | |
| 15113 } | |
| 15114 return OneByteString::raw(dststr); | |
| 15115 } | |
| 15116 return OneByteString::raw(Symbols::Empty()); | |
| 15117 } | |
|
turnidge
2013/12/19 20:39:29
Is there a way to avoid the code duplication by ha
Cutch
2013/12/19 21:53:58
Percent encoding is only defined on OneByteStrings
| |
| 15118 | |
| 15119 | |
| 15120 RawOneByteString* OneByteString::DecodeURI(const String& str) { | |
| 15121 intptr_t len = str.Length(); | |
| 15122 if (len > 0) { | |
| 15123 intptr_t num_escapes = 0; | |
| 15124 for (intptr_t i = 0; i < len; i++) { | |
| 15125 if (IsPercent(*CharAddr(str, i))) { | |
| 15126 num_escapes += 2; | |
| 15127 } | |
| 15128 } | |
| 15129 ASSERT(len - num_escapes > 0); | |
| 15130 const String& dststr = String::Handle( | |
| 15131 OneByteString::New(len - num_escapes, Heap::kNew)); | |
| 15132 intptr_t index = 0; | |
| 15133 for (intptr_t i = 0; i < len;) { | |
| 15134 if (IsPercent(*CharAddr(str, i))) { | |
| 15135 int32_t ch1 = *CharAddr(str, i + 1); | |
| 15136 int32_t ch2 = *CharAddr(str, i + 2); | |
| 15137 int32_t merged = MergeHexCharacters(ch1, ch2); | |
| 15138 *(CharAddr(dststr, index)) = merged; | |
| 15139 i += 3; | |
| 15140 } else { | |
| 15141 *(CharAddr(dststr, index)) = *CharAddr(str, i); | |
| 15142 i += 1; | |
| 15143 } | |
| 15144 index++; | |
| 15145 } | |
| 15146 return OneByteString::raw(dststr); | |
| 15147 } | |
| 15148 return OneByteString::raw(Symbols::Empty()); | |
| 15149 } | |
| 15150 | |
| 15151 | |
| 15152 RawOneByteString* ExternalOneByteString::DecodeURI(const String& str) { | |
| 15153 intptr_t len = str.Length(); | |
| 15154 if (len > 0) { | |
| 15155 intptr_t num_escapes = 0; | |
| 15156 for (intptr_t i = 0; i < len; i++) { | |
| 15157 if (IsPercent(*CharAddr(str, i))) { | |
| 15158 num_escapes += 2; | |
| 15159 } | |
| 15160 } | |
| 15161 ASSERT(len - num_escapes > 0); | |
| 15162 const String& dststr = String::Handle( | |
| 15163 OneByteString::New(len - num_escapes, Heap::kNew)); | |
| 15164 intptr_t index = 0; | |
| 15165 for (intptr_t i = 0; i < len;) { | |
| 15166 if (IsPercent(*CharAddr(str, i))) { | |
| 15167 int32_t ch1 = *CharAddr(str, i + 1); | |
| 15168 int32_t ch2 = *CharAddr(str, i + 2); | |
| 15169 int32_t merged = MergeHexCharacters(ch1, ch2); | |
| 15170 *(OneByteString::CharAddr(dststr, index)) = merged; | |
| 15171 i += 3; | |
| 15172 } else { | |
| 15173 *(OneByteString::CharAddr(dststr, index)) = *CharAddr(str, i); | |
| 15174 i += 1; | |
| 15175 } | |
| 15176 index++; | |
| 15177 } | |
| 15178 return OneByteString::raw(dststr); | |
| 15179 } | |
| 15180 return OneByteString::raw(Symbols::Empty()); | |
| 15181 } | |
| 15182 | |
| 15183 | |
| 14895 RawOneByteString* OneByteString::New(intptr_t len, | 15184 RawOneByteString* OneByteString::New(intptr_t len, |
| 14896 Heap::Space space) { | 15185 Heap::Space space) { |
| 14897 ASSERT(Isolate::Current() == Dart::vm_isolate() || | 15186 ASSERT(Isolate::Current() == Dart::vm_isolate() || |
| 14898 Isolate::Current()->object_store()->one_byte_string_class() != | 15187 Isolate::Current()->object_store()->one_byte_string_class() != |
| 14899 Class::null()); | 15188 Class::null()); |
| 14900 if (len < 0 || len > kMaxElements) { | 15189 if (len < 0 || len > kMaxElements) { |
| 14901 // This should be caught before we reach here. | 15190 // This should be caught before we reach here. |
| 14902 FATAL1("Fatal error in OneByteString::New: invalid len %" Pd "\n", len); | 15191 FATAL1("Fatal error in OneByteString::New: invalid len %" Pd "\n", len); |
| 14903 } | 15192 } |
| 14904 { | 15193 { |
| (...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16512 return "_MirrorReference"; | 16801 return "_MirrorReference"; |
| 16513 } | 16802 } |
| 16514 | 16803 |
| 16515 | 16804 |
| 16516 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 16805 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 16517 Instance::PrintToJSONStream(stream, ref); | 16806 Instance::PrintToJSONStream(stream, ref); |
| 16518 } | 16807 } |
| 16519 | 16808 |
| 16520 | 16809 |
| 16521 } // namespace dart | 16810 } // namespace dart |
| OLD | NEW |