blob: 4dc0bc19d45921fbe2e4ffdf800f82dc14ac416f [file] [log] [blame]
Avi Drissman60039d42022-09-13 21:49:051// Copyright 2014 The Chromium Authors
yangguo0d0c4762014-10-15 07:23:262// 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
avi2d124c02015-12-23 06:36:428#include <stddef.h>
9
Hyowon Kim05bf2f62024-01-05 00:35:2210#include <string_view>
11
yangguo0d0c4762014-10-15 07:23:2612#include "base/compiler_specific.h"
Dan Elphick500ba5f2021-09-24 13:17:2413#include "v8/include/v8-primitive.h"
yangguo0d0c4762014-10-15 07:23:2614
15namespace 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.
20class StaticV8ExternalOneByteStringResource
21 : public v8::String::ExternalOneByteStringResource {
22 public:
Hyowon Kim05bf2f62024-01-05 00:35:2223 explicit StaticV8ExternalOneByteStringResource(std::string_view buffer);
dcheng9168b2f2014-10-21 12:38:2424 ~StaticV8ExternalOneByteStringResource() override;
yangguo0d0c4762014-10-15 07:23:2625
dcheng9168b2f2014-10-21 12:38:2426 const char* data() const override;
27 size_t length() const override;
yangguo0d0c4762014-10-15 07:23:2628
29 private:
Hyowon Kim05bf2f62024-01-05 00:35:2230 std::string_view buffer_;
yangguo0d0c4762014-10-15 07:23:2631};
32
33} // namespace extensions
34
35#endif // EXTENSIONS_RENDERER_STATIC_V8_EXTERNAL_ONE_BYTE_STRING_RESOURCE_H_