Closed Bug 34187 Opened 24 years ago Closed 24 years ago

eval is not a property of the Global Object

Categories

(Core :: JavaScript Engine, defect, P3)

x86
Windows 98
defect

Tracking

()

RESOLVED FIXED

People

(Reporter: yugo, Assigned: rogerl)

Details

eval is defined as a property of Object Object in jsobj.c.
But eval is a property of the Global Object. (15.1.2.1 eval (x))

Though
    alert(hasOwnProperty("parseInt"));
shows "true",
    alert(hasOwnProperty("eval"));
shows "false".
and Rhino doesn't even seem to support hasOwnProperty. Yikes.
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Added missing functions to Rhino - all is well there now. Here's a patch for 
Monkey, jsobj.c:

@@ -1238,6 +1238,7 @@
 js_InitObjectClass(JSContext *cx, JSObject *obj)
 {
     JSObject *proto;
+    jsval fval;

 #if JS_HAS_SHARP_VARS
     JS_ASSERT(sizeof(jsatomid) * JS_BITS_PER_BYTE >= ATOM_INDEX_LIMIT_LOG2 + 
1);
@@ -1251,6 +1252,17 @@
        return NULL;
     }
 #endif
+
+    /* ECMA (15.1.2.1) says 'eval' is also a property of the global object. */
+    if (!OBJ_GET_PROPERTY(cx, proto, (jsid)cx->runtime->atomState.evalAtom,
+                          &fval)) {
+        return NULL;
+    }
+    if (!OBJ_DEFINE_PROPERTY(cx, obj, (jsid)cx->runtime->atomState.evalAtom,
+                             fval, NULL, NULL, 0, NULL)) {
+       return NULL;
+    }
+
     return proto;
 }
Fix checed in.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.