r9536 - helma-ng/trunk/src/org/helma/javascript

[email protected]
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20090223120112.2CFA63D0D6@mia>
Author: hannes
Date: 2009-02-23 13:01:12 +0100 (Mon, 23 Feb 2009)
New Revision: 9536

Modified:
   helma-ng/trunk/src/org/helma/javascript/StaticMethods.java
Log:
Do not use Map interface for property descriptor in Object.defineProperty() as it causes wrapper values to be unwrapped.

Details at http://dev.helma.org/trac/helma/changeset/9536

Modified: helma-ng/trunk/src/org/helma/javascript/StaticMethods.java
===================================================================
--- helma-ng/trunk/src/org/helma/javascript/StaticMethods.java	2009-02-23 12:01:10 UTC (rev 9535)
+++ helma-ng/trunk/src/org/helma/javascript/StaticMethods.java	2009-02-23 12:01:12 UTC (rev 9536)
@@ -19,8 +19,6 @@
 import org.helma.util.ScriptUtils;
 import org.mozilla.javascript.*;
 
-import java.util.Map;
-
 /**
  * This class contains the native functions Helma adds to the global scope.
  */
@@ -53,7 +51,7 @@
         ScriptUtils.checkArguments(args, 3, 3);
         ScriptableObject obj = ScriptUtils.getScriptableArgument(args, 0);
         String propname = ScriptUtils.getStringArgument(args, 1);
-        Map desc = ScriptUtils.getMapArgument(args, 2);
+        Scriptable desc = ScriptUtils.getScriptableArgument(args, 2);
         if (obj == null || propname == null || desc == null) {
             throw new IllegalArgumentException();
         }
@@ -67,18 +65,26 @@
         public final Callable getter, setter;
         public final boolean enumerable, configurable, writable;
 
-        public PropertyDescriptor(Map desc) {
-            value = desc.get("value");
-            getter = (Callable) desc.get("getter");
-            setter = (Callable) desc.get("setter");
-            enumerable = ScriptRuntime.toBoolean(desc.get("enumerable"));
-            configurable = ScriptRuntime.toBoolean(desc.get("configurable"));
-            writable = ScriptRuntime.toBoolean(desc.get("writable"));
+        public PropertyDescriptor(Scriptable desc) {
+            value = getDescriptorValue("value", desc);
+            getter = (Callable) getDescriptorValue("getter", desc);
+            setter = (Callable) getDescriptorValue("setter", desc);
+            enumerable = ScriptRuntime.toBoolean(getDescriptorValue("enumerable", desc));
+            configurable = ScriptRuntime.toBoolean(getDescriptorValue("configurable", desc));
+            writable = ScriptRuntime.toBoolean(getDescriptorValue("writable", desc));
             if (value != null && (getter != null || setter != null)) {
                 throw new IllegalArgumentException("Only one of value or getter/setter must be defined");
             }
         }
 
+        public Object getDescriptorValue(String propName, Scriptable desc) {
+            Object value = desc.get(propName, desc);
+            if (value == Undefined.instance || value == UniqueTag.NOT_FOUND) {
+                return null;
+            }
+            return value;
+        }
+
         public int getAttributes() {
             int attr = 0;
             if (!enumerable) attr |= ScriptableObject.DONTENUM;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.