Permalink
Browse files

Change all Math.* properties to be readonly.

  • Loading branch information...
1 parent 25c5aee commit fb1a08fb89b933c3fff4a80377fecfaf531e3b29 @lance lance committed Aug 31, 2012
Showing with 21 additions and 9 deletions.
  1. +21 −9 src/main/java/org/dynjs/runtime/builtins/Math.java
@@ -2,31 +2,43 @@
import org.dynjs.runtime.DynObject;
import org.dynjs.runtime.GlobalObject;
+import org.dynjs.runtime.PropertyDescriptor;
import org.dynjs.runtime.builtins.math.Abs;
import org.dynjs.runtime.builtins.math.Acos;
import org.dynjs.runtime.builtins.math.Asin;
import org.dynjs.runtime.builtins.types.number.DynNumber;
public class Math extends DynObject {
- public Math(GlobalObject globalObject) {
+ public Math(final GlobalObject globalObject) {
super(globalObject);
// Math properties 15.8.1
- put(null, "E", new DynNumber(globalObject, java.lang.Math.E), false); // 15.8.1.1
- put(null, "LN10", new DynNumber(globalObject, java.lang.Math.log(10)), false); // 15.8.1.2
- put(null, "LN2", new DynNumber(globalObject, java.lang.Math.log(2)), false); // 15.8.1.3
- put(null, "LOG2E", new DynNumber(globalObject, java.lang.Math.log(java.lang.Math.E)/java.lang.Math.log(2)), false); // 15.8.1.4
- put(null, "LOG10E", new DynNumber(globalObject, java.lang.Math.log10(java.lang.Math.E)), false); // 15.8.1.5
- put(null, "PI", new DynNumber(globalObject, java.lang.Math.PI), false); // 15.8.1.6
- put(null, "SQRT1_2", new DynNumber(globalObject, java.lang.Math.sqrt(0.5f)), false); // 15.8.1.7
- put(null, "SQRT2", new DynNumber(globalObject, java.lang.Math.sqrt(2.0f)), false); // 15.8.1.8
+ defineReadOnlyProperty( globalObject, "E", java.lang.Math.E ); // 15.8.1.1
+ defineReadOnlyProperty( globalObject, "LN10", java.lang.Math.log(10) ); // 15.8.1.2
+ defineReadOnlyProperty( globalObject, "LN2", java.lang.Math.log(2) ); // 15.8.1.3
+ defineReadOnlyProperty( globalObject, "LOG2E", java.lang.Math.log(java.lang.Math.E)/java.lang.Math.log(2) ); // 15.8.1.4
+ defineReadOnlyProperty( globalObject, "LOG10E", java.lang.Math.log10(java.lang.Math.E) ); // 15.8.1.5
+ defineReadOnlyProperty( globalObject, "PI", java.lang.Math.PI ); // 15.8.1.6
+ defineReadOnlyProperty( globalObject, "SQRT1_2", java.lang.Math.sqrt(0.5f) ); // 15.8.1.7
+ defineReadOnlyProperty( globalObject, "SQRT2", java.lang.Math.sqrt(2.0f) ); // 15.8.1.8
// Math functions 15.8.2
put(null, "abs", new Abs(globalObject), false); // 15.8.2.1
put(null, "acos", new Acos(globalObject), false); // 15.8.2.2
put(null, "asin", new Asin(globalObject), false); // 15.8.2.3
}
+ protected void defineReadOnlyProperty(final GlobalObject globalObject, String name, final Number value) {
+ this.defineOwnProperty( null, name, new PropertyDescriptor() {
+ {
+ set("Value", new DynNumber(globalObject, value));
+ set("Writable", false);
+ set("Enumerable", false);
+ set("Configurable", false);
+ }
+ }, false );
+ }
+
}

0 comments on commit fb1a08f

Please sign in to comment.