| Index: runtime/bin/secure_socket_macos.h
|
| diff --git a/runtime/bin/secure_socket_macos.h b/runtime/bin/secure_socket_macos.h
|
| index e78321cda96a4c86d98eaff139ac7a570dfb0b9e..c088d8c7e84d8730a3a2850a7069b4e9510d5379 100644
|
| --- a/runtime/bin/secure_socket_macos.h
|
| +++ b/runtime/bin/secure_socket_macos.h
|
| @@ -143,6 +143,64 @@ class SSLFilter {
|
| DISALLOW_COPY_AND_ASSIGN(SSLFilter);
|
| };
|
|
|
| +// Where the argument to the constructor is the handle for an object
|
| +// implementing List<int>, this class creates a scope in which the memory
|
| +// backing the list can be accessed.
|
| +//
|
| +// Do not make Dart_ API calls while in a ScopedMemBuffer.
|
| +// Do not call Dart_PropagateError while in a ScopedMemBuffer.
|
| +class ScopedMemBuffer {
|
| + public:
|
| + explicit ScopedMemBuffer(Dart_Handle object) {
|
| + if (!Dart_IsTypedData(object) && !Dart_IsList(object)) {
|
| + Dart_ThrowException(DartUtils::NewDartArgumentError(
|
| + "Argument is not a List<int>"));
|
| + }
|
| +
|
| + uint8_t* bytes = NULL;
|
| + intptr_t bytes_len = 0;
|
| + bool is_typed_data = false;
|
| + if (Dart_IsTypedData(object)) {
|
| + is_typed_data = true;
|
| + Dart_TypedData_Type typ;
|
| + ThrowIfError(Dart_TypedDataAcquireData(
|
| + object,
|
| + &typ,
|
| + reinterpret_cast<void**>(&bytes),
|
| + &bytes_len));
|
| + } else {
|
| + ASSERT(Dart_IsList(object));
|
| + ThrowIfError(Dart_ListLength(object, &bytes_len));
|
| + bytes = Dart_ScopeAllocate(bytes_len);
|
| + ASSERT(bytes != NULL);
|
| + ThrowIfError(Dart_ListGetAsBytes(object, 0, bytes, bytes_len));
|
| + }
|
| +
|
| + object_ = object;
|
| + bytes_ = bytes;
|
| + bytes_len_ = bytes_len;
|
| + is_typed_data_ = is_typed_data;
|
| + }
|
| +
|
| + ~ScopedMemBuffer() {
|
| + if (is_typed_data_) {
|
| + ThrowIfError(Dart_TypedDataReleaseData(object_));
|
| + }
|
| + }
|
| +
|
| + uint8_t* get() const { return bytes_; }
|
| + intptr_t length() const { return bytes_len_; }
|
| +
|
| + private:
|
| + Dart_Handle object_;
|
| + uint8_t* bytes_;
|
| + intptr_t bytes_len_;
|
| + bool is_typed_data_;
|
| +
|
| + DISALLOW_ALLOCATION();
|
| + DISALLOW_COPY_AND_ASSIGN(ScopedMemBuffer);
|
| +};
|
| +
|
| } // namespace bin
|
| } // namespace dart
|
|
|
|
|