ref: 89793bba03c1a94b631a64d8d2bf761d43bf66c5
parent: 066a06741cfc3f9dba4e01b38d67d79d700cae8a
author: Tor Andersson <tor.andersson@artifex.com>
date: Thu Jun 2 07:52:56 EDT 2016
Fix Object.prototype.toString when called with null or undefined this.
--- a/jsobject.c
+++ b/jsobject.c
@@ -20,29 +20,35 @@
static void Op_toString(js_State *J)
{
- js_Object *self = js_toobject(J, 0);
- switch (self->type) {
- case JS_COBJECT: js_pushliteral(J, "[object Object]"); break;
- case JS_CARRAY: js_pushliteral(J, "[object Array]"); break;
- case JS_CFUNCTION: js_pushliteral(J, "[object Function]"); break;
- case JS_CSCRIPT: js_pushliteral(J, "[object Function]"); break;
- case JS_CCFUNCTION: js_pushliteral(J, "[object Function]"); break;
- case JS_CERROR: js_pushliteral(J, "[object Error]"); break;
- case JS_CBOOLEAN: js_pushliteral(J, "[object Boolean]"); break;
- case JS_CNUMBER: js_pushliteral(J, "[object Number]"); break;
- case JS_CSTRING: js_pushliteral(J, "[object String]"); break;
- case JS_CREGEXP: js_pushliteral(J, "[object RegExp]"); break;
- case JS_CDATE: js_pushliteral(J, "[object Date]"); break;
- case JS_CMATH: js_pushliteral(J, "[object Math]"); break;
- case JS_CJSON: js_pushliteral(J, "[object JSON]"); break;
- case JS_CITERATOR: js_pushliteral(J, "[Iterator]"); break;
- case JS_CUSERDATA:
- js_pushliteral(J, "[object ");
- js_pushliteral(J, self->u.user.tag);
- js_concat(J);
- js_pushliteral(J, "]");
- js_concat(J);
- break;
+ if (js_isundefined(J, 0))
+ js_pushliteral(J, "[object Undefined]");
+ else if (js_isnull(J, 0))
+ js_pushliteral(J, "[object Null]");
+ else {
+ js_Object *self = js_toobject(J, 0);
+ switch (self->type) {
+ case JS_COBJECT: js_pushliteral(J, "[object Object]"); break;
+ case JS_CARRAY: js_pushliteral(J, "[object Array]"); break;
+ case JS_CFUNCTION: js_pushliteral(J, "[object Function]"); break;
+ case JS_CSCRIPT: js_pushliteral(J, "[object Function]"); break;
+ case JS_CCFUNCTION: js_pushliteral(J, "[object Function]"); break;
+ case JS_CERROR: js_pushliteral(J, "[object Error]"); break;
+ case JS_CBOOLEAN: js_pushliteral(J, "[object Boolean]"); break;
+ case JS_CNUMBER: js_pushliteral(J, "[object Number]"); break;
+ case JS_CSTRING: js_pushliteral(J, "[object String]"); break;
+ case JS_CREGEXP: js_pushliteral(J, "[object RegExp]"); break;
+ case JS_CDATE: js_pushliteral(J, "[object Date]"); break;
+ case JS_CMATH: js_pushliteral(J, "[object Math]"); break;
+ case JS_CJSON: js_pushliteral(J, "[object JSON]"); break;
+ case JS_CITERATOR: js_pushliteral(J, "[Iterator]"); break;
+ case JS_CUSERDATA:
+ js_pushliteral(J, "[object ");
+ js_pushliteral(J, self->u.user.tag);
+ js_concat(J);
+ js_pushliteral(J, "]");
+ js_concat(J);
+ break;
+ }
}
}