mirror of
https://github.com/ccxvii/mujs.git
synced 2026-02-06 01:41:37 +08:00
Garbage collect (some) strings.
Separate literal/interned and garbage collected string types in js_Value. js_pushintern/js_tointern are convenience functions to push/pop strings and automatically intern them (so that the string pointers are guaranteed to be stable). js_pushliteral should push stable strings (either interned or actual literals). js_pushstring will copy the string into garbage collected memory. The pointer returned by js_tostring is guaranteed to be stable only for as long as the stack slot it came from remains untouched. Some uses will always cause a string to be interned: * Using it as a property name. * Wrapping it in a new String() object. * Strings returned by toString(). ToPrimitive must not clobber the stack, so the result has to be unrooted. * Numbers converted to strings (by js_tostring) Likewise, we have nowhere to store the temporary string here. Passing in a scratch buffer to js_tostring could help this problem. Mostly an issue with array accesses (OP_GETPROP, etc) so an auxiliary function and we don't have to clutter the API needlessly.
This commit is contained in:
@@ -55,7 +55,7 @@ static void jsB_new_String(js_State *J)
|
||||
|
||||
static void jsB_String(js_State *J)
|
||||
{
|
||||
js_pushliteral(J, js_gettop(J) > 1 ? js_tostring(J, 1) : "");
|
||||
js_pushstring(J, js_gettop(J) > 1 ? js_tostring(J, 1) : "");
|
||||
}
|
||||
|
||||
static void Sp_toString(js_State *J)
|
||||
|
||||
Reference in New Issue
Block a user