Skip to content

Panic in YT JS challenge code: "must be declarative environment" #4531

@ivankra

Description

@ivankra

I tried running boa f6601a0 on a sample of YouTube's JavaScript challenge code obtained via yt-dlp and got panic "must be declarative environment" at core/engine/src/vm/opcode/define/mod.rs:82

To Reproduce

yt-dlp.js: https://gist.github.com/ivankra/a950b2c37db48c66fe5dceb0acd8d874

$ RUST_BACKTRACE=1 ./boa ./yt-dlp.js 
The application panicked (crashed).
Message:  must be declarative environment
Location: core/engine/src/vm/opcode/define/mod.rs:82

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 8 frames hidden ⋮                               
   9: core::panicking::panic_display::hdb91bec8c8265aa5
      at /rustc/f8297e351a40c1439a467bbbb6879088047f50b3/library/core/src/panicking.rs:259
  10: core::option::expect_failed::hea2bb3a7ccc7c5b3
      at /rustc/f8297e351a40c1439a467bbbb6879088047f50b3/library/core/src/option.rs:2178
  11: core::option::Option<T>::expect::hf4f065c840341c7e
      at /rustc/f8297e351a40c1439a467bbbb6879088047f50b3/library/core/src/option.rs:965
  12: boa_engine::environments::runtime::EnvironmentStack::put_lexical_value::h698370a81a436903
      at /src/core/engine/src/environments/runtime/mod.rs:278
  13: boa_engine::vm::opcode::define::PutLexicalValue::operation::h55fb2e4e26729726
      at /src/core/engine/src/vm/opcode/define/mod.rs:82
  14: boa_engine::vm::opcode::handle_put_lexical_value::h1a2ac59231bc1a42
      at /src/core/engine/src/vm/opcode/mod.rs:313
  15: boa_engine::vm::opcode::<impl boa_engine::context::Context>::execute_bytecode_instruction::h05cf762f1186ea14
      at /src/core/engine/src/vm/opcode/mod.rs:464
  16: core::ops::function::FnOnce::call_once::h15bd6b9f79691c90
      at /rustc/f8297e351a40c1439a467bbbb6879088047f50b3/library/core/src/ops/function.rs:250
  17: boa_engine::vm::<impl boa_engine::context::Context>::execute_instruction::hb992a7a7d5b634cb
      at /src/core/engine/src/vm/mod.rs:639
  18: boa_engine::vm::<impl boa_engine::context::Context>::execute_one::h7f99e5770ebfcf61
      at /src/core/engine/src/vm/mod.rs:660
  19: boa_engine::vm::<impl boa_engine::context::Context>::run::h428d40eb0428985d
      at /src/core/engine/src/vm/mod.rs:848
  20: boa_engine::object::operations::<impl boa_engine::object::jsobject::JsObject>::call::h9219d3b571b7e32d
      at /src/core/engine/src/object/operations.rs:422
  21: boa_engine::builtins::function::BuiltInFunctionObject::call::h290c30fa8c6dbea5
      at /src/core/engine/src/builtins/function/mod.rs:825
  22: boa_engine::native_function::NativeFunction::call::h2679bf4efd98dfc6
      at /src/core/engine/src/native_function/mod.rs:305
  23: boa_engine::native_function::native_function_call::h9bfa96f586caf69a
      at /src/core/engine/src/native_function/mod.rs:367
  24: boa_engine::object::internal_methods::CallValue::resolve::hb669511035227ac1
      at /src/core/engine/src/object/internal_methods/mod.rs:493
  25: boa_engine::vm::opcode::call::Call::operation::h9c59a8ba9346a1ea
      at /src/core/engine/src/vm/opcode/call/mod.rs:196
  26: boa_engine::vm::opcode::handle_call::hbf3b728e7aa522d4
      at /src/core/engine/src/vm/opcode/mod.rs:313
  27: boa_engine::vm::opcode::<impl boa_engine::context::Context>::execute_bytecode_instruction::h05cf762f1186ea14
      at /src/core/engine/src/vm/opcode/mod.rs:464
  28: core::ops::function::FnOnce::call_once::h15bd6b9f79691c90
      at /rustc/f8297e351a40c1439a467bbbb6879088047f50b3/library/core/src/ops/function.rs:250
  29: boa_engine::vm::<impl boa_engine::context::Context>::execute_instruction::hb992a7a7d5b634cb
      at /src/core/engine/src/vm/mod.rs:639
  30: boa_engine::vm::<impl boa_engine::context::Context>::execute_one::h7f99e5770ebfcf61
      at /src/core/engine/src/vm/mod.rs:660
  31: boa_engine::vm::<impl boa_engine::context::Context>::run::h428d40eb0428985d
      at /src/core/engine/src/vm/mod.rs:848
  32: boa_engine::object::operations::<impl boa_engine::object::jsobject::JsObject>::call::h9219d3b571b7e32d
      at /src/core/engine/src/object/operations.rs:422
  33: boa_engine::builtins::array::Array::map::h55624803156c60f9
      at /src/core/engine/src/builtins/array/mod.rs:1427
  34: boa_engine::native_function::NativeFunction::call::h2679bf4efd98dfc6
      at /src/core/engine/src/native_function/mod.rs:305
  35: boa_engine::native_function::native_function_call::h9bfa96f586caf69a
      at /src/core/engine/src/native_function/mod.rs:367
  36: boa_engine::object::internal_methods::CallValue::resolve::hb669511035227ac1
      at /src/core/engine/src/object/internal_methods/mod.rs:493
  37: boa_engine::vm::opcode::call::Call::operation::h9c59a8ba9346a1ea
      at /src/core/engine/src/vm/opcode/call/mod.rs:196
  38: boa_engine::vm::opcode::handle_call::hbf3b728e7aa522d4
      at /src/core/engine/src/vm/opcode/mod.rs:313
  39: boa_engine::vm::opcode::<impl boa_engine::context::Context>::execute_bytecode_instruction::h05cf762f1186ea14
      at /src/core/engine/src/vm/opcode/mod.rs:464
  40: core::ops::function::FnOnce::call_once::h15bd6b9f79691c90
      at /rustc/f8297e351a40c1439a467bbbb6879088047f50b3/library/core/src/ops/function.rs:250
  41: boa_engine::vm::<impl boa_engine::context::Context>::execute_instruction::hb992a7a7d5b634cb
      at /src/core/engine/src/vm/mod.rs:639
  42: boa_engine::vm::<impl boa_engine::context::Context>::execute_one::h7f99e5770ebfcf61
      at /src/core/engine/src/vm/mod.rs:660
  43: boa_engine::vm::<impl boa_engine::context::Context>::run::h428d40eb0428985d
      at /src/core/engine/src/vm/mod.rs:848
  44: boa_engine::object::operations::<impl boa_engine::object::jsobject::JsObject>::call::h9219d3b571b7e32d
      at /src/core/engine/src/object/operations.rs:422
  45: boa_engine::builtins::array::Array::map::h55624803156c60f9
      at /src/core/engine/src/builtins/array/mod.rs:1427
  46: boa_engine::native_function::NativeFunction::call::h2679bf4efd98dfc6
      at /src/core/engine/src/native_function/mod.rs:305
  47: boa_engine::native_function::native_function_call::h9bfa96f586caf69a
      at /src/core/engine/src/native_function/mod.rs:367
  48: boa_engine::object::internal_methods::CallValue::resolve::hb669511035227ac1
      at /src/core/engine/src/object/internal_methods/mod.rs:493
  49: boa_engine::vm::opcode::call::Call::operation::h9c59a8ba9346a1ea
      at /src/core/engine/src/vm/opcode/call/mod.rs:196
  50: boa_engine::vm::opcode::handle_call::hbf3b728e7aa522d4
      at /src/core/engine/src/vm/opcode/mod.rs:313
  51: boa_engine::vm::opcode::<impl boa_engine::context::Context>::execute_bytecode_instruction::h05cf762f1186ea14
      at /src/core/engine/src/vm/opcode/mod.rs:464
  52: core::ops::function::FnOnce::call_once::h15bd6b9f79691c90
      at /rustc/f8297e351a40c1439a467bbbb6879088047f50b3/library/core/src/ops/function.rs:250
  53: boa_engine::vm::<impl boa_engine::context::Context>::execute_instruction::hb992a7a7d5b634cb
      at /src/core/engine/src/vm/mod.rs:639
  54: boa_engine::vm::<impl boa_engine::context::Context>::execute_one::h7f99e5770ebfcf61
      at /src/core/engine/src/vm/mod.rs:660
  55: boa_engine::vm::<impl boa_engine::context::Context>::run::h428d40eb0428985d
      at /src/core/engine/src/vm/mod.rs:848
  56: boa_engine::script::Script::evaluate::h15bd132c8b385ea8
      at /src/core/engine/src/script.rs:172
  57: boa_engine::context::Context::eval::haea02080314dff13
      at /src/core/engine/src/context/mod.rs:204
  58: boa::evaluate_file::he88b73b71dce4993
      at /src/cli/src/main.rs:378
  59: boa::evaluate_files::h2a38775a20ee7dd5
      at /src/cli/src/main.rs:399
  60: boa::main::hddbab26b99c49f9c
      at /src/cli/src/main.rs:447
  61: core::ops::function::FnOnce::call_once::h0511cd2a60b85073
      at /rustc/f8297e351a40c1439a467bbbb6879088047f50b3/library/core/src/ops/function.rs:250
  62: std::sys::backtrace::__rust_begin_short_backtrace::hb1192448aad66b27
      at /rustc/f8297e351a40c1439a467bbbb6879088047f50b3/library/std/src/sys/backtrace.rs:158
                                ⋮ 14 frames hidden ⋮                              

Expected behavior
It shouldn't crash.

On a related note, from the running time before crash (~1.5 minutes) it looks like boa maybe is missing rope string optimization? It could really benefit this benchmark, speeding up execution by couple orders of magnitude - brimstone (another Rust engine) seems to have it and finishes in 5s.

Build environment (please complete the following information):

  • OS: Linux
  • Version: Debian GNU/Linux 13 (trixie) - current arm64 docker's image on docker.io/debian:stable
  • Target triple: aarch64-linux-gnu
  • Rustc version: rustc 1.91.0 (f8297e351 2025-10-28)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions