shithub: libmujs

Download patch

ref: 6ba9e94d028d1158d405d7b10363a7b3b8514a02
parent: a859bc67d575b3f509b0e52a2a929d3d1d1841b6
author: Tor Andersson <[email protected]>
date: Wed Jan 15 12:03:01 EST 2014

js_pushlstring() for pushing literal (and interned strings).

js_pushstring() will intern its argument first.

--- a/jsrun.c
+++ b/jsrun.c
@@ -69,7 +69,7 @@
 	++top;
 }
 
-void js_pushstring(js_State *J, const char *v)
+void js_pushlstring(js_State *J, const char *v)
 {
 	stack[top].type = JS_TSTRING;
 	stack[top].u.string = v;
@@ -76,6 +76,13 @@
 	++top;
 }
 
+void js_pushstring(js_State *J, const char *v)
+{
+	stack[top].type = JS_TSTRING;
+	stack[top].u.string = js_intern(J, v);
+	++top;
+}
+
 void js_pushobject(js_State *J, js_Object *v)
 {
 	stack[top].type = JS_TOBJECT;
@@ -261,7 +268,7 @@
 		case OP_NUMBER_1: js_pushnumber(J, 1); break;
 		case OP_NUMBER_X: js_pushnumber(J, *pc++); break;
 		case OP_NUMBER: js_pushnumber(J, NT[*pc++]); break;
-		case OP_STRING: js_pushstring(J, ST[*pc++]); break;
+		case OP_STRING: js_pushlstring(J, ST[*pc++]); break;
 		// case OP_CLOSURE: break;
 
 		case OP_UNDEF: js_pushundefined(J); break;
@@ -339,7 +346,7 @@
 				ref = js_nextproperty(J, obj, js_tostring(J, -1));
 			if (ref) {
 				js_pop(J, 1);
-				js_pushstring(J, ref->name);
+				js_pushlstring(J, ref->name);
 				js_pushboolean(J, 1);
 			} else {
 				js_pop(J, 2);