static_v8_external_one_byte_string_resource.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef EXTENSIONS_RENDERER_STATIC_V8_EXTERNAL_ONE_BYTE_STRING_RESOURCE_H_
  5. #define EXTENSIONS_RENDERER_STATIC_V8_EXTERNAL_ONE_BYTE_STRING_RESOURCE_H_
  6. #include <stddef.h>
  7. #include "base/compiler_specific.h"
  8. #include "base/strings/string_piece.h"
  9. #include "v8/include/v8-primitive.h"
  10. namespace extensions {
  11. // A very simple implementation of v8::ExternalAsciiStringResource that just
  12. // wraps a buffer. The buffer must outlive the v8 runtime instance this resource
  13. // is used in.
  14. class StaticV8ExternalOneByteStringResource
  15. : public v8::String::ExternalOneByteStringResource {
  16. public:
  17. explicit StaticV8ExternalOneByteStringResource(
  18. const base::StringPiece& buffer);
  19. ~StaticV8ExternalOneByteStringResource() override;
  20. const char* data() const override;
  21. size_t length() const override;
  22. private:
  23. base::StringPiece buffer_;
  24. };
  25. } // namespace extensions
  26. #endif // EXTENSIONS_RENDERER_STATIC_V8_EXTERNAL_ONE_BYTE_STRING_RESOURCE_H_