Chromium Code Reviews| Index: runtime/vm/object.cc |
| diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
| index a00c5049b767f339f3ba80d2c723d1f042c4a7fb..e809b0cb98ce03f84f6869c0f69c7d0a62a231fd 100644 |
| --- a/runtime/vm/object.cc |
| +++ b/runtime/vm/object.cc |
| @@ -397,6 +397,9 @@ void Object::Init(Isolate* isolate) { |
| cls = Class::New<Bool>(); |
| object_store->set_bool_class(cls); |
| + cls = Class::New<ByteBuffer>(); |
| + object_store->set_byte_buffer_class(cls); |
| + |
| cls = Class::New<UnhandledException>(); |
| object_store->set_unhandled_exception_class(cls); |
| @@ -527,6 +530,12 @@ void Object::Init(Isolate* isolate) { |
| cls.set_script(script); |
| core_lib.AddClass(cls); |
| + name = String::NewSymbol("ByteBuffer"); |
| + cls = object_store->byte_buffer_class(); |
| + cls.set_name(name); |
| + cls.set_script(script); |
| + core_lib.AddClass(cls); |
| + |
| name = String::NewSymbol("Function"); |
| cls = Class::NewInterface(name, script); |
| core_lib.AddClass(cls); |
| @@ -625,6 +634,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); |
| @@ -1109,6 +1121,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(); |
| @@ -6662,6 +6677,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); |
|
Ivan Posva
2011/11/16 22:50:01
Please do not use ints as boolean:
return memcmp(.
cshapiro
2011/11/17 03:17:02
Certainly. Done.
|
| +} |
| + |
| + |
| +const char* ByteBuffer::ToCString() const { |
| + return "ByteBuffer"; |
| +} |
| + |
| + |
| RawClosure* Closure::New(const Function& function, |
| const Context& context, |
| Heap::Space space) { |