Skip to content

Commit bd1d237

Browse files
committed
fix: marshal Undefined and SafeString DOM values in Lua
`domValue_push` handled `Null`, `Boolean`, `Integer`, `String`, `Array`, and `Object`, and aborted via `MRDOCS_UNREACHABLE` for any other kind. Reading a field whose value is `Undefined` or `SafeString` therefore crashed a Lua script. `Undefined` is common: a symbol with no name (the global namespace, for instance) has an `Undefined` name, so a Lua script that reads `symbol.name` aborted the build. So, map `Undefined` to `nil`, as `Null` already is, and push a `SafeString` as its bytes, the way `String` is handled. This matches the JavaScript bridge.
1 parent 224c795 commit bd1d237

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/lib/Support/Lua.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,20 @@ domValue_push(
643643
{
644644
case dom::Kind::Null:
645645
return lua_pushnil(A);
646+
case dom::Kind::Undefined:
647+
// Lua has a single nullary value, so a missing field maps to
648+
// `nil` just as `Null` does. A read of an absent field (for
649+
// example the global namespace's name) yields `Undefined` and
650+
// must not abort.
651+
return lua_pushnil(A);
646652
case dom::Kind::Boolean:
647653
return lua_pushboolean(A, value.getBool());
648654
case dom::Kind::Integer:
649655
return lua_pushnumber(A, value.getInteger());
650656
case dom::Kind::String:
657+
case dom::Kind::SafeString:
658+
// A `SafeString` is a string already marked safe for an output
659+
// format; to a Lua script it is just its bytes.
651660
return luaM_pushstring(A, value.getString());
652661
case dom::Kind::Array:
653662
return domArray_push(A, value.getArray());

0 commit comments

Comments
 (0)