pub struct Obj {
pub props: PropMap<Value>,
pub kind: ObjKind,
pub proto: Option<ObjRef>,
pub rare: Option<Box<RareData>>,
pub gc_slot: u32,
pub flags: u8,
}Expand description
ヒープオブジェクト本体。名前付きプロパティ + プロトタイプ + 種別。
Fields§
§props: PropMap<Value>§kind: ObjKind§proto: Option<ObjRef>§rare: Option<Box<RareData>>§gc_slot: u32循環ゴミ回収(cycle_gc)の台帳の番号(未登録は NO_GC_SLOT)。
flags: u8状態フラグ(frozen, sealed, non_extensible, null_proto を 1 バイトに集約)。
Implementations§
Source§impl Obj
impl Obj
pub fn new(kind: ObjKind) -> Self
pub fn is_frozen(&self) -> bool
pub fn set_frozen(&mut self, v: bool)
pub fn is_sealed(&self) -> bool
pub fn set_sealed(&mut self, v: bool)
pub fn is_non_extensible(&self) -> bool
pub fn set_non_extensible(&mut self, v: bool)
pub fn is_null_proto(&self) -> bool
pub fn set_null_proto(&mut self, v: bool)
pub fn rare_data(&self) -> Option<&RareData>
Sourcepub fn function_class_name(&self) -> &'static str
pub fn function_class_name(&self) -> &'static str
関数の「種類の名前」(Object.getPrototypeOf(fn).constructor.name)。普通は Function。
Sourcepub fn is_error_obj(&self) -> bool
pub fn is_error_obj(&self) -> bool
[[ErrorData]] 内部スロットを持つ Error インスタンスか。
Sourcepub fn error_stack(&self) -> Option<&str>
pub fn error_stack(&self) -> Option<&str>
[[ErrorData]] 内部スロットのスタック文字列。
Sourcepub fn set_error_stack(&mut self, s: String)
pub fn set_error_stack(&mut self, s: String)
[[ErrorData]] 内部スロットのスタック文字列を設定する。
pub fn has_private_brand(&self, brand: u64) -> bool
pub fn add_private_brand(&mut self, brand: u64)
pub fn has_private_field(&self, brand: u64, name: &str) -> bool
pub fn get_private_field(&self, brand: u64, name: &str) -> Option<&Value>
pub fn set_private_field(&mut self, brand: u64, name: &str, val: Value) -> bool
pub fn define_private_field( &mut self, brand: u64, name: Rc<str>, val: Value, ) -> bool
pub fn rare_data_mut(&mut self) -> &mut RareData
pub fn has_rare_props(&self) -> bool
pub fn accessors(&self) -> Option<&PropMap<Accessor>>
pub fn accessors_mut(&mut self) -> &mut PropMap<Accessor>
pub fn get_accessor(&self, key: &str) -> Option<&Accessor>
pub fn has_any_accessor(&self) -> bool
pub fn has_accessor(&self, key: &str) -> bool
pub fn get_getter(&self, key: &str) -> Option<Value>
pub fn get_setter(&self, key: &str) -> Option<Value>
pub fn insert_accessor(&mut self, key: impl Into<PropKey>, acc: Accessor)
pub fn remove_accessor(&mut self, key: &str) -> Option<Accessor>
pub fn attrs(&self) -> Option<&PropMap<PropertyAttributes>>
pub fn attrs_mut(&mut self) -> &mut PropMap<PropertyAttributes>
pub fn get_attr(&self, key: &str) -> Option<PropertyAttributes>
pub fn get_attr_or_default(&self, key: &str) -> PropertyAttributes
Sourcepub fn has_virtual_fn_prop(&self, key: &str) -> bool
pub fn has_virtual_fn_prop(&self, key: &str) -> bool
この関数オブジェクトが未削除・未実体化の仮想自前プロパティ(name または length)を持つか。
Sourcepub fn delete_virtual_fn_prop(&mut self, key: &str)
pub fn delete_virtual_fn_prop(&mut self, key: &str)
関数の仮想自前プロパティ(name / length)を削除済み(または props/accessors 実体化済み)としてマークする。
pub fn insert_attr(&mut self, key: impl Into<PropKey>, attr: PropertyAttributes)
pub fn remove_attr(&mut self, key: &str) -> Option<PropertyAttributes>
pub fn holes(&self) -> Option<&[bool]>
pub fn set_holes(&mut self, holes: Option<Box<Vec<bool>>>)
pub fn clear_holes(&mut self)
Sourcepub fn fn_prototype(o: &ObjRef) -> Option<Value>
pub fn fn_prototype(o: &ObjRef) -> Option<Value>
関数の prototype(通常の function は初回参照時に作る)。
【2026-10-24】以前は関数を作るたびに prototype のオブジェクトを作っていた。ほとんどの
関数(コールバック・メソッド)はコンストラクタとして使われないのに、関数 1 つにつき
オブジェクトが 2 つになり、しかも f.prototype.constructor === f の循環で参照カウントでは
解放されず循環回収待ちになった(YouTube の視聴ページでヒープが尽きた一因)。
pub fn plain() -> ObjRef
pub fn bytes(store: ByteStore) -> ObjRef
Sourcepub fn grow_array(&mut self, new_len: usize) -> bool
pub fn grow_array(&mut self, new_len: usize) -> bool
配列を new_len 要素まで伸ばす。増えた要素は穴(値は undefined だが要素として存在しない)。
上限 MAX_DENSE_ARRAY_LEN を超えるなら何もせず false(配列は要素を詰めて持つので、疎な巨大配列は作れない)。
【2026-11-12】以前は a[4294967294] = 1 や a.length = 2**32 - 1 でそのまま確保しようとして
(68GB)、確保の失敗でアプリごと落ちていた。また、伸びた分が穴にならず a.length = 5 の後の
a.indexOf(undefined) が -1 にならなかった。
Sourcepub fn clear_hole(&mut self, i: usize)
pub fn clear_hole(&mut self, i: usize)
i 番目の穴の印を消す(そこへ値を書いたとき。undefined を書いても穴ではなくなる)。
Sourcepub fn is_enumerable(&self, key: &str) -> bool
pub fn is_enumerable(&self, key: &str) -> bool
自身のプロパティ key を列挙するか(属性の表が無いものの既定を含む)。
【2026-11-16】属性を持たない次の 2 つは、仕様どおり列挙しない(属性の表を作らずに判定する。 関数ごとに表を持たせると、YouTube の数万のコンストラクタで数 MB 増えるため):
- 関数の
prototype。 F.prototype.constructor(値が関数で、その関数のprototypeがこのオブジェクト)。 以前はfor (k in new F)にconstructorが出ていた。
Sourcepub fn hide_props(&mut self, keys: &[&str])
pub fn hide_props(&mut self, keys: &[&str])
自身のプロパティ keys のうち、あるものを「列挙しない」にする(書き込み・設定の変更はできるまま)。
例外オブジェクトの message・stack や、組み込みが付けるプロパティ用。
pub fn array(items: Vec<Value>) -> ObjRef
pub fn array_push(&mut self, v: Value)
pub fn function(data: FunctionData) -> ObjRef
pub fn function_rc(data: Rc<FunctionData>) -> ObjRef
pub fn native(name: &str, func: NativeFn) -> ObjRef
Sourcepub fn gen_return() -> ObjRef
pub fn gen_return() -> ObjRef
ジェネレータの return の合図(ObjKind::GenReturn)。