| Index: runtime/vm/object.cc
|
| diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
|
| index 2908ca1ff038b0131f2fb9fc9d495b476190ce13..0dea4d9102b465f1214b47a7ca9b2c8724d712bc 100644
|
| --- a/runtime/vm/object.cc
|
| +++ b/runtime/vm/object.cc
|
| @@ -485,7 +485,8 @@ void Object::Init(Isolate* isolate) {
|
| const Script& script = Script::Handle(Bootstrap::LoadScript());
|
|
|
| // Allocate and initialize the Object class and type.
|
| - // Object class is the only pre-allocated non-interface in the core library.
|
| + // The Object and ByteBuffer classes are the only pre-allocated
|
| + // non-interface classes in the core library.
|
| cls = Class::New<Instance>();
|
| object_store->set_object_class(cls);
|
| cls.set_name(String::Handle(String::NewSymbol("Object")));
|
| @@ -495,6 +496,12 @@ void Object::Init(Isolate* isolate) {
|
| type = Type::NewNonParameterizedType(cls);
|
| object_store->set_object_type(type);
|
|
|
| + cls = Class::New<ByteBuffer>();
|
| + object_store->set_byte_buffer_class(cls);
|
| + cls.set_name(String::Handle(String::NewSymbol("ByteBuffer")));
|
| + cls.set_script(script);
|
| + core_lib.AddClass(cls);
|
| +
|
| // Set the super type of class Stacktrace to Object type so that the
|
| // 'toString' method is implemented.
|
| cls = object_store->stacktrace_class();
|
| @@ -601,6 +608,9 @@ void Object::InitFromSnapshot(Isolate* isolate) {
|
| cls = Class::New<ImmutableArray>();
|
| object_store->set_immutable_array_class(cls);
|
|
|
| + cls = Class::New<ByteBuffer>();
|
| + object_store->set_byte_buffer_class(cls);
|
| +
|
| cls = Class::New<Instance>();
|
| object_store->set_object_class(cls);
|
|
|
| @@ -1112,6 +1122,9 @@ RawClass* Class::GetClass(ObjectKind kind) {
|
| case kImmutableArray:
|
| ASSERT(object_store->immutable_array_class() != Class::null());
|
| return object_store->immutable_array_class();
|
| + case kByteBuffer:
|
| + ASSERT(object_store->byte_buffer_class() != Class::null());
|
| + return object_store->byte_buffer_class();
|
| case kStacktrace:
|
| ASSERT(object_store->stacktrace_class() != Class::null());
|
| return object_store->stacktrace_class();
|
| @@ -6698,6 +6711,53 @@ const char* ImmutableArray::ToCString() const {
|
| }
|
|
|
|
|
| +RawByteBuffer* ByteBuffer::New(uint8_t* data,
|
| + intptr_t len,
|
| + Heap::Space space) {
|
| + Isolate* isolate = Isolate::Current();
|
| + const Class& byte_buffer_class =
|
| + Class::Handle(isolate->object_store()->byte_buffer_class());
|
| + ByteBuffer& result = ByteBuffer::Handle();
|
| + {
|
| + RawObject* raw = Object::Allocate(byte_buffer_class,
|
| + ByteBuffer::InstanceSize(),
|
| + space);
|
| + NoGCScope no_gc;
|
| + result ^= raw;
|
| + result.SetLength(len);
|
| + result.SetData(data);
|
| + }
|
| + return result.raw();
|
| +}
|
| +
|
| +
|
| +bool ByteBuffer::Equals(const Instance& other) const {
|
| + if (this->raw() == other.raw()) {
|
| + // Both handles point to the same raw instance.
|
| + return true;
|
| + }
|
| +
|
| + if (!other.IsByteBuffer() || other.IsNull()) {
|
| + return false;
|
| + }
|
| +
|
| + ByteBuffer& other_array = ByteBuffer::Handle();
|
| + other_array ^= other.raw();
|
| +
|
| + intptr_t len = this->Length();
|
| + if (len != other_array.Length()) {
|
| + return false;
|
| + }
|
| +
|
| + return memcmp(this->Addr<uint8_t>(0), other_array.Addr<uint8_t>(0), len) == 0;
|
| +}
|
| +
|
| +
|
| +const char* ByteBuffer::ToCString() const {
|
| + return "ByteBuffer";
|
| +}
|
| +
|
| +
|
| RawClosure* Closure::New(const Function& function,
|
| const Context& context,
|
| Heap::Space space) {
|
|
|