Skip to main content

Obj

Struct Obj 

Source
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

Source

pub fn new(kind: ObjKind) -> Self

Source

pub fn is_frozen(&self) -> bool

Source

pub fn set_frozen(&mut self, v: bool)

Source

pub fn is_sealed(&self) -> bool

Source

pub fn set_sealed(&mut self, v: bool)

Source

pub fn is_non_extensible(&self) -> bool

Source

pub fn set_non_extensible(&mut self, v: bool)

Source

pub fn is_null_proto(&self) -> bool

Source

pub fn set_null_proto(&mut self, v: bool)

Source

pub fn rare_data(&self) -> Option<&RareData>

Source

pub fn function_class_name(&self) -> &'static str

関数の「種類の名前」(Object.getPrototypeOf(fn).constructor.name)。普通は Function。

Source

pub fn primitive(&self) -> Option<&Value>

値の包みオブジェクトの中身(包みでなければ None)。

Source

pub fn is_error_obj(&self) -> bool

[[ErrorData]] 内部スロットを持つ Error インスタンスか。

Source

pub fn error_stack(&self) -> Option<&str>

[[ErrorData]] 内部スロットのスタック文字列。

Source

pub fn set_error_stack(&mut self, s: String)

[[ErrorData]] 内部スロットのスタック文字列を設定する。

Source

pub fn has_private_brand(&self, brand: u64) -> bool

Source

pub fn add_private_brand(&mut self, brand: u64)

Source

pub fn has_private_field(&self, brand: u64, name: &str) -> bool

Source

pub fn get_private_field(&self, brand: u64, name: &str) -> Option<&Value>

Source

pub fn set_private_field(&mut self, brand: u64, name: &str, val: Value) -> bool

Source

pub fn define_private_field( &mut self, brand: u64, name: Rc<str>, val: Value, ) -> bool

Source

pub fn rare_data_mut(&mut self) -> &mut RareData

Source

pub fn has_rare_props(&self) -> bool

Source

pub fn accessors(&self) -> Option<&PropMap<Accessor>>

Source

pub fn accessors_mut(&mut self) -> &mut PropMap<Accessor>

Source

pub fn get_accessor(&self, key: &str) -> Option<&Accessor>

Source

pub fn has_any_accessor(&self) -> bool

Source

pub fn has_accessor(&self, key: &str) -> bool

Source

pub fn get_getter(&self, key: &str) -> Option<Value>

Source

pub fn get_setter(&self, key: &str) -> Option<Value>

Source

pub fn insert_accessor(&mut self, key: impl Into<PropKey>, acc: Accessor)

Source

pub fn remove_accessor(&mut self, key: &str) -> Option<Accessor>

Source

pub fn attrs(&self) -> Option<&PropMap<PropertyAttributes>>

Source

pub fn attrs_mut(&mut self) -> &mut PropMap<PropertyAttributes>

Source

pub fn get_attr(&self, key: &str) -> Option<PropertyAttributes>

Source

pub fn get_attr_or_default(&self, key: &str) -> PropertyAttributes

Source

pub fn has_virtual_fn_prop(&self, key: &str) -> bool

この関数オブジェクトが未削除・未実体化の仮想自前プロパティ(name または length)を持つか。

Source

pub fn delete_virtual_fn_prop(&mut self, key: &str)

関数の仮想自前プロパティ(name / length)を削除済み(または props/accessors 実体化済み)としてマークする。

Source

pub fn insert_attr(&mut self, key: impl Into<PropKey>, attr: PropertyAttributes)

Source

pub fn remove_attr(&mut self, key: &str) -> Option<PropertyAttributes>

Source

pub fn holes(&self) -> Option<&[bool]>

Source

pub fn set_holes(&mut self, holes: Option<Box<Vec<bool>>>)

Source

pub fn clear_holes(&mut self)

Source

pub fn fn_prototype(o: &ObjRef) -> Option<Value>

関数の prototype(通常の function は初回参照時に作る)。

【2026-10-24】以前は関数を作るたびに prototype のオブジェクトを作っていた。ほとんどの 関数(コールバック・メソッド)はコンストラクタとして使われないのに、関数 1 つにつき オブジェクトが 2 つになり、しかも f.prototype.constructor === f の循環で参照カウントでは 解放されず循環回収待ちになった(YouTube の視聴ページでヒープが尽きた一因)。

Source

pub fn plain() -> ObjRef

Source

pub fn bytes(store: ByteStore) -> ObjRef

Source

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 にならなかった。

Source

pub fn clear_hole(&mut self, i: usize)

i 番目の穴の印を消す(そこへ値を書いたとき。undefined を書いても穴ではなくなる)。

Source

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 が出ていた。
Source

pub fn hide_props(&mut self, keys: &[&str])

自身のプロパティ keys のうち、あるものを「列挙しない」にする(書き込み・設定の変更はできるまま)。 例外オブジェクトの message・stack や、組み込みが付けるプロパティ用。

Source

pub fn is_hole(&self, i: usize) -> bool

配列の i 番目が穴か。

Source

pub fn hole_mask(&self) -> Vec<bool>

配列の穴の一覧(len 要素。穴が無ければ空)。

Source

pub fn array(items: Vec<Value>) -> ObjRef

Source

pub fn array_push(&mut self, v: Value)

Source

pub fn function(data: FunctionData) -> ObjRef

Source

pub fn function_rc(data: Rc<FunctionData>) -> ObjRef

Source

pub fn native(name: &str, func: NativeFn) -> ObjRef

Source

pub fn iter_obj() -> ObjRef

軽量イテレータ(ObjKind::Iter)。

Source

pub fn gen_return() -> ObjRef

ジェネレータの return の合図(ObjKind::GenReturn)。

Source

pub fn host_ref(h: HostRef) -> ObjRef

ホスト物のハンドルを作る(DOM 要素の Obj::dom は dom_bridge.rs)。

Source

pub fn private_desc(pd: PrivateDescriptor) -> ObjRef

Source

pub fn map_obj(entries: Vec<(Value, Value)>) -> ObjRef

Source

pub fn set_obj(items: Vec<Value>) -> ObjRef

Source

pub fn promise(state: Rc<RefCell<PromiseState>>) -> ObjRef

Source

pub fn resolver(state: Rc<RefCell<PromiseState>>, reject: bool) -> ObjRef

Source

pub fn generator(state: GenState) -> ObjRef

Source

pub fn regexp(data: RegExpData) -> ObjRef

Source

pub fn proxy(target: ObjRef, handler: ObjRef) -> ObjRef

Source

pub fn date_obj(epoch_ms: f64) -> ObjRef

Source

pub fn bound(target: Value, bound_this: Value, bound_args: Vec<Value>) -> ObjRef

Source

pub fn clear_references(&mut self)

Source

pub fn is_callable(&self) -> bool

Source§

impl Obj

Source

pub fn dom(node_idx: usize) -> ObjRef

DOM 要素のハンドルを作る(ノード index 1 つ。同じノードのハンドルは === で等しい)。

Source

pub fn dom_host(class: u8, id: usize) -> ObjRef

DOM のプロキシ(style・classList・document など。HOST_* の番号と id)を作る。

Trait Implementations§

Source§

impl Drop for Obj

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Obj

§

impl !Send for Obj

§

impl !Sync for Obj

§

impl !UnwindSafe for Obj

§

impl Freeze for Obj

§

impl Unpin for Obj

§

impl UnsafeUnpin for Obj

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.