Skip to content

Commit

Permalink
Add helper to dump the current JS stack. (#543)
Browse files Browse the repository at this point in the history
* Add helper to dump the current JS stack.

Signed-off-by: Josh Matthews <[email protected]>

* Bump mozjs_sys version.

Signed-off-by: Josh Matthews <[email protected]>

---------

Signed-off-by: Josh Matthews <[email protected]>
  • Loading branch information
jdm authored Dec 25, 2024
1 parent ce24cb7 commit e68fdba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mozjs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "mozjs_sys"
description = "System crate for the Mozilla SpiderMonkey JavaScript engine."
repository.workspace = true
version = "0.128.6-0"
version = "0.128.6-1"
authors = ["Mozilla"]
links = "mozjs"
build = "build.rs"
Expand Down
13 changes: 13 additions & 0 deletions mozjs-sys/src/jsglue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "js/experimental/JSStencil.h"
#include "js/experimental/JitInfo.h"
#include "js/experimental/TypedData.h"
#include "js/friend/DumpFunctions.h"
#include "js/friend/ErrorMessages.h"
#include "jsapi.h"
#include "jsfriendapi.h"
Expand Down Expand Up @@ -1071,4 +1072,16 @@ void SetAccessorPropertyDescriptor(
desc.set(JS::PropertyDescriptor::Accessor(getter, setter, attrs));
}

void DumpJSStack(JSContext* cx, bool showArgs, bool showLocals,
bool showThisProps) {
JS::AutoSaveExceptionState state(cx);

JS::UniqueChars buf =
JS::FormatStackDump(cx, showArgs, showLocals, showThisProps);

state.restore();

printf("%s\n", buf.get());
}

} // extern "C"

0 comments on commit e68fdba

Please sign in to comment.