11cb0ef41Sopenharmony_ci// Copyright 2021 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef INCLUDE_V8_CONTAINER_H_ 61cb0ef41Sopenharmony_ci#define INCLUDE_V8_CONTAINER_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include <stddef.h> 91cb0ef41Sopenharmony_ci#include <stdint.h> 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci#include "v8-local-handle.h" // NOLINT(build/include_directory) 121cb0ef41Sopenharmony_ci#include "v8-object.h" // NOLINT(build/include_directory) 131cb0ef41Sopenharmony_ci#include "v8config.h" // NOLINT(build/include_directory) 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cinamespace v8 { 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciclass Context; 181cb0ef41Sopenharmony_ciclass Isolate; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci/** 211cb0ef41Sopenharmony_ci * An instance of the built-in array constructor (ECMA-262, 15.4.2). 221cb0ef41Sopenharmony_ci */ 231cb0ef41Sopenharmony_ciclass V8_EXPORT Array : public Object { 241cb0ef41Sopenharmony_ci public: 251cb0ef41Sopenharmony_ci uint32_t Length() const; 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci /** 281cb0ef41Sopenharmony_ci * Creates a JavaScript array with the given length. If the length 291cb0ef41Sopenharmony_ci * is negative the returned array will have length 0. 301cb0ef41Sopenharmony_ci */ 311cb0ef41Sopenharmony_ci static Local<Array> New(Isolate* isolate, int length = 0); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci /** 341cb0ef41Sopenharmony_ci * Creates a JavaScript array out of a Local<Value> array in C++ 351cb0ef41Sopenharmony_ci * with a known length. 361cb0ef41Sopenharmony_ci */ 371cb0ef41Sopenharmony_ci static Local<Array> New(Isolate* isolate, Local<Value>* elements, 381cb0ef41Sopenharmony_ci size_t length); 391cb0ef41Sopenharmony_ci V8_INLINE static Array* Cast(Value* value) { 401cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_CHECKS 411cb0ef41Sopenharmony_ci CheckCast(value); 421cb0ef41Sopenharmony_ci#endif 431cb0ef41Sopenharmony_ci return static_cast<Array*>(value); 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci private: 471cb0ef41Sopenharmony_ci Array(); 481cb0ef41Sopenharmony_ci static void CheckCast(Value* obj); 491cb0ef41Sopenharmony_ci}; 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci/** 521cb0ef41Sopenharmony_ci * An instance of the built-in Map constructor (ECMA-262, 6th Edition, 23.1.1). 531cb0ef41Sopenharmony_ci */ 541cb0ef41Sopenharmony_ciclass V8_EXPORT Map : public Object { 551cb0ef41Sopenharmony_ci public: 561cb0ef41Sopenharmony_ci size_t Size() const; 571cb0ef41Sopenharmony_ci void Clear(); 581cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context, 591cb0ef41Sopenharmony_ci Local<Value> key); 601cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT MaybeLocal<Map> Set(Local<Context> context, 611cb0ef41Sopenharmony_ci Local<Value> key, 621cb0ef41Sopenharmony_ci Local<Value> value); 631cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, 641cb0ef41Sopenharmony_ci Local<Value> key); 651cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context, 661cb0ef41Sopenharmony_ci Local<Value> key); 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci /** 691cb0ef41Sopenharmony_ci * Returns an array of length Size() * 2, where index N is the Nth key and 701cb0ef41Sopenharmony_ci * index N + 1 is the Nth value. 711cb0ef41Sopenharmony_ci */ 721cb0ef41Sopenharmony_ci Local<Array> AsArray() const; 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci /** 751cb0ef41Sopenharmony_ci * Creates a new empty Map. 761cb0ef41Sopenharmony_ci */ 771cb0ef41Sopenharmony_ci static Local<Map> New(Isolate* isolate); 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci V8_INLINE static Map* Cast(Value* value) { 801cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_CHECKS 811cb0ef41Sopenharmony_ci CheckCast(value); 821cb0ef41Sopenharmony_ci#endif 831cb0ef41Sopenharmony_ci return static_cast<Map*>(value); 841cb0ef41Sopenharmony_ci } 851cb0ef41Sopenharmony_ci 861cb0ef41Sopenharmony_ci private: 871cb0ef41Sopenharmony_ci Map(); 881cb0ef41Sopenharmony_ci static void CheckCast(Value* obj); 891cb0ef41Sopenharmony_ci}; 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ci/** 921cb0ef41Sopenharmony_ci * An instance of the built-in Set constructor (ECMA-262, 6th Edition, 23.2.1). 931cb0ef41Sopenharmony_ci */ 941cb0ef41Sopenharmony_ciclass V8_EXPORT Set : public Object { 951cb0ef41Sopenharmony_ci public: 961cb0ef41Sopenharmony_ci size_t Size() const; 971cb0ef41Sopenharmony_ci void Clear(); 981cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT MaybeLocal<Set> Add(Local<Context> context, 991cb0ef41Sopenharmony_ci Local<Value> key); 1001cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, 1011cb0ef41Sopenharmony_ci Local<Value> key); 1021cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context, 1031cb0ef41Sopenharmony_ci Local<Value> key); 1041cb0ef41Sopenharmony_ci 1051cb0ef41Sopenharmony_ci /** 1061cb0ef41Sopenharmony_ci * Returns an array of the keys in this Set. 1071cb0ef41Sopenharmony_ci */ 1081cb0ef41Sopenharmony_ci Local<Array> AsArray() const; 1091cb0ef41Sopenharmony_ci 1101cb0ef41Sopenharmony_ci /** 1111cb0ef41Sopenharmony_ci * Creates a new empty Set. 1121cb0ef41Sopenharmony_ci */ 1131cb0ef41Sopenharmony_ci static Local<Set> New(Isolate* isolate); 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ci V8_INLINE static Set* Cast(Value* value) { 1161cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_CHECKS 1171cb0ef41Sopenharmony_ci CheckCast(value); 1181cb0ef41Sopenharmony_ci#endif 1191cb0ef41Sopenharmony_ci return static_cast<Set*>(value); 1201cb0ef41Sopenharmony_ci } 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_ci private: 1231cb0ef41Sopenharmony_ci Set(); 1241cb0ef41Sopenharmony_ci static void CheckCast(Value* obj); 1251cb0ef41Sopenharmony_ci}; 1261cb0ef41Sopenharmony_ci 1271cb0ef41Sopenharmony_ci} // namespace v8 1281cb0ef41Sopenharmony_ci 1291cb0ef41Sopenharmony_ci#endif // INCLUDE_V8_CONTAINER_H_ 130