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/snapshot.h" | 5 #include "vm/snapshot.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/bootstrap.h" | 8 #include "vm/bootstrap.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
(...skipping 2497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2508 } | 2508 } |
2509 // Not a closure of a top level method or static function, throw an | 2509 // Not a closure of a top level method or static function, throw an |
2510 // exception as we do not allow these objects to be serialized. | 2510 // exception as we do not allow these objects to be serialized. |
2511 HANDLESCOPE(thread()); | 2511 HANDLESCOPE(thread()); |
2512 | 2512 |
2513 const Class& clazz = Class::Handle(isolate(), cls); | 2513 const Class& clazz = Class::Handle(isolate(), cls); |
2514 const Function& errorFunc = Function::Handle(isolate(), func); | 2514 const Function& errorFunc = Function::Handle(isolate(), func); |
2515 ASSERT(!errorFunc.IsNull()); | 2515 ASSERT(!errorFunc.IsNull()); |
2516 | 2516 |
2517 // All other closures are errors. | 2517 // All other closures are errors. |
2518 const char* format = "Illegal argument in isolate message" | |
2519 " : (object is a closure - %s %s)"; | |
2520 UnmarkAll(); // Unmark objects now as we are about to print stuff. | 2518 UnmarkAll(); // Unmark objects now as we are about to print stuff. |
2521 intptr_t len = OS::SNPrint(NULL, 0, format, | 2519 char* chars = OS::SCreate(thread()->zone(), |
2522 clazz.ToCString(), errorFunc.ToCString()) + 1; | 2520 "Illegal argument in isolate message : (object is a closure - %s %s)", |
2523 char* chars = thread()->zone()->Alloc<char>(len); | 2521 clazz.ToCString(), errorFunc.ToCString()); |
2524 OS::SNPrint(chars, len, format, clazz.ToCString(), errorFunc.ToCString()); | |
2525 SetWriteException(Exceptions::kArgument, chars); | 2522 SetWriteException(Exceptions::kArgument, chars); |
2526 } | 2523 } |
2527 return Function::null(); | 2524 return Function::null(); |
2528 } | 2525 } |
2529 | 2526 |
2530 | 2527 |
2531 RawClass* SnapshotWriter::GetFunctionOwner(RawFunction* func) { | 2528 RawClass* SnapshotWriter::GetFunctionOwner(RawFunction* func) { |
2532 RawObject* owner = func->ptr()->owner_; | 2529 RawObject* owner = func->ptr()->owner_; |
2533 uword tags = GetObjectTags(owner); | 2530 uword tags = GetObjectTags(owner); |
2534 intptr_t class_id = RawObject::ClassIdTag::decode(tags); | 2531 intptr_t class_id = RawObject::ClassIdTag::decode(tags); |
2535 if (class_id == kClassCid) { | 2532 if (class_id == kClassCid) { |
2536 return reinterpret_cast<RawClass*>(owner); | 2533 return reinterpret_cast<RawClass*>(owner); |
2537 } | 2534 } |
2538 ASSERT(class_id == kPatchClassCid); | 2535 ASSERT(class_id == kPatchClassCid); |
2539 return reinterpret_cast<RawPatchClass*>(owner)->ptr()->patched_class_; | 2536 return reinterpret_cast<RawPatchClass*>(owner)->ptr()->patched_class_; |
2540 } | 2537 } |
2541 | 2538 |
2542 | 2539 |
2543 void SnapshotWriter::CheckForNativeFields(RawClass* cls) { | 2540 void SnapshotWriter::CheckForNativeFields(RawClass* cls) { |
2544 if (cls->ptr()->num_native_fields_ != 0) { | 2541 if (cls->ptr()->num_native_fields_ != 0) { |
2545 // We do not allow objects with native fields in an isolate message. | 2542 // We do not allow objects with native fields in an isolate message. |
2546 HANDLESCOPE(thread()); | 2543 HANDLESCOPE(thread()); |
2547 const char* format = "Illegal argument in isolate message" | |
2548 " : (object extends NativeWrapper - %s)"; | |
2549 UnmarkAll(); // Unmark objects now as we are about to print stuff. | 2544 UnmarkAll(); // Unmark objects now as we are about to print stuff. |
2550 const Class& clazz = Class::Handle(isolate(), cls); | 2545 const Class& clazz = Class::Handle(isolate(), cls); |
2551 intptr_t len = OS::SNPrint(NULL, 0, format, clazz.ToCString()) + 1; | 2546 char* chars = OS::SCreate(thread()->zone(), |
2552 char* chars = thread()->zone()->Alloc<char>(len); | 2547 "Illegal argument in isolate message" |
2553 OS::SNPrint(chars, len, format, clazz.ToCString()); | 2548 " : (object extends NativeWrapper - %s)", |
| 2549 clazz.ToCString()); |
2554 SetWriteException(Exceptions::kArgument, chars); | 2550 SetWriteException(Exceptions::kArgument, chars); |
2555 } | 2551 } |
2556 } | 2552 } |
2557 | 2553 |
2558 | 2554 |
2559 void SnapshotWriter::SetWriteException(Exceptions::ExceptionType type, | 2555 void SnapshotWriter::SetWriteException(Exceptions::ExceptionType type, |
2560 const char* msg) { | 2556 const char* msg) { |
2561 set_exception_type(type); | 2557 set_exception_type(type); |
2562 set_exception_msg(msg); | 2558 set_exception_msg(msg); |
2563 // The more specific error is set up in SnapshotWriter::ThrowException(). | 2559 // The more specific error is set up in SnapshotWriter::ThrowException(). |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2788 NoSafepointScope no_safepoint; | 2784 NoSafepointScope no_safepoint; |
2789 WriteObject(obj.raw()); | 2785 WriteObject(obj.raw()); |
2790 UnmarkAll(); | 2786 UnmarkAll(); |
2791 } else { | 2787 } else { |
2792 ThrowException(exception_type(), exception_msg()); | 2788 ThrowException(exception_type(), exception_msg()); |
2793 } | 2789 } |
2794 } | 2790 } |
2795 | 2791 |
2796 | 2792 |
2797 } // namespace dart | 2793 } // namespace dart |
OLD | NEW |