Avi Drissman | 60039d4 | 2022-09-13 21:49:05 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors |
yangguo | 0d0c476 | 2014-10-15 07:23:26 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef EXTENSIONS_RENDERER_STATIC_V8_EXTERNAL_ONE_BYTE_STRING_RESOURCE_H_ |
| 6 | #define EXTENSIONS_RENDERER_STATIC_V8_EXTERNAL_ONE_BYTE_STRING_RESOURCE_H_ |
| 7 | |
avi | 2d124c0 | 2015-12-23 06:36:42 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
Hyowon Kim | 05bf2f6 | 2024-01-05 00:35:22 | [diff] [blame] | 10 | #include <string_view> |
| 11 | |
yangguo | 0d0c476 | 2014-10-15 07:23:26 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
Dan Elphick | 500ba5f | 2021-09-24 13:17:24 | [diff] [blame] | 13 | #include "v8/include/v8-primitive.h" |
yangguo | 0d0c476 | 2014-10-15 07:23:26 | [diff] [blame] | 14 | |
| 15 | namespace extensions { |
| 16 | |
| 17 | // A very simple implementation of v8::ExternalAsciiStringResource that just |
| 18 | // wraps a buffer. The buffer must outlive the v8 runtime instance this resource |
| 19 | // is used in. |
| 20 | class StaticV8ExternalOneByteStringResource |
| 21 | : public v8::String::ExternalOneByteStringResource { |
| 22 | public: |
Hyowon Kim | 05bf2f6 | 2024-01-05 00:35:22 | [diff] [blame] | 23 | explicit StaticV8ExternalOneByteStringResource(std::string_view buffer); |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 24 | ~StaticV8ExternalOneByteStringResource() override; |
yangguo | 0d0c476 | 2014-10-15 07:23:26 | [diff] [blame] | 25 | |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 26 | const char* data() const override; |
| 27 | size_t length() const override; |
yangguo | 0d0c476 | 2014-10-15 07:23:26 | [diff] [blame] | 28 | |
| 29 | private: |
Hyowon Kim | 05bf2f6 | 2024-01-05 00:35:22 | [diff] [blame] | 30 | std::string_view buffer_; |
yangguo | 0d0c476 | 2014-10-15 07:23:26 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | } // namespace extensions |
| 34 | |
| 35 | #endif // EXTENSIONS_RENDERER_STATIC_V8_EXTERNAL_ONE_BYTE_STRING_RESOURCE_H_ |