8012190: Global scope should be initialized lazily

Wed, 25 Mar 2015 14:36:22 +0530

author
sundar
date
Wed, 25 Mar 2015 14:36:22 +0530
changeset 1267
e597c5975dac
parent 1266
c847904b447b
child 1268
f41b7c3954d4

8012190: Global scope should be initialized lazily
Reviewed-by: lagergren, hannesw, attila

src/jdk/nashorn/internal/objects/Global.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeDate.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeRegExp.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/objects/Global.java	Tue Mar 24 13:59:31 2015 +0530
     1.2 +++ b/src/jdk/nashorn/internal/objects/Global.java	Wed Mar 25 14:36:22 2015 +0530
     1.3 @@ -54,8 +54,10 @@
     1.4  import jdk.nashorn.api.scripting.ScriptObjectMirror;
     1.5  import jdk.nashorn.internal.lookup.Lookup;
     1.6  import jdk.nashorn.internal.objects.annotations.Attribute;
     1.7 +import jdk.nashorn.internal.objects.annotations.Getter;
     1.8  import jdk.nashorn.internal.objects.annotations.Property;
     1.9  import jdk.nashorn.internal.objects.annotations.ScriptClass;
    1.10 +import jdk.nashorn.internal.objects.annotations.Setter;
    1.11  import jdk.nashorn.internal.runtime.Context;
    1.12  import jdk.nashorn.internal.runtime.ECMAErrors;
    1.13  import jdk.nashorn.internal.runtime.GlobalConstants;
    1.14 @@ -89,6 +91,9 @@
    1.15      private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class);
    1.16      private final InvokeByName VALUE_OF  = new InvokeByName("valueOf",  ScriptObject.class);
    1.17  
    1.18 +    // placeholder value for lazily initialized global objects
    1.19 +    private static final Object LAZY_SENTINEL = new Object();
    1.20 +
    1.21      /**
    1.22       * Optimistic builtin names that require switchpoint invalidation
    1.23       * upon assignment. Overly conservative, but works for now, to avoid
    1.24 @@ -214,20 +219,76 @@
    1.25      public volatile Object number;
    1.26  
    1.27      /** ECMA 15.1.4.7 Date constructor */
    1.28 -    @Property(name = "Date", attributes = Attribute.NOT_ENUMERABLE)
    1.29 -    public volatile Object date;
    1.30 +    @Getter(name = "Date", attributes = Attribute.NOT_ENUMERABLE)
    1.31 +    public static Object getDate(final Object self) {
    1.32 +        final Global global = Global.instanceFrom(self);
    1.33 +        if (global.date == LAZY_SENTINEL) {
    1.34 +            global.date = global.getBuiltinDate();
    1.35 +        }
    1.36 +        return global.date;
    1.37 +    }
    1.38 +
    1.39 +    @Setter(name = "Date", attributes = Attribute.NOT_ENUMERABLE)
    1.40 +    public static void setDate(final Object self, final Object value) {
    1.41 +        final Global global = Global.instanceFrom(self);
    1.42 +        global.date = value;
    1.43 +    }
    1.44 +
    1.45 +    private volatile Object date = LAZY_SENTINEL;
    1.46  
    1.47      /** ECMA 15.1.4.8 RegExp constructor */
    1.48 -    @Property(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE)
    1.49 -    public volatile Object regexp;
    1.50 +    @Getter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE)
    1.51 +    public static Object getRegExp(final Object self) {
    1.52 +        final Global global = Global.instanceFrom(self);
    1.53 +        if (global.regexp == LAZY_SENTINEL) {
    1.54 +            global.regexp = global.getBuiltinRegExp();
    1.55 +        }
    1.56 +        return global.regexp;
    1.57 +    }
    1.58 +
    1.59 +    @Setter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE)
    1.60 +    public static void setRegExp(final Object self, final Object value) {
    1.61 +        final Global global = Global.instanceFrom(self);
    1.62 +        global.regexp = value;
    1.63 +    }
    1.64 +
    1.65 +    private volatile Object regexp = LAZY_SENTINEL;
    1.66  
    1.67      /** ECMA 15.12 - The JSON object */
    1.68 -    @Property(name = "JSON", attributes = Attribute.NOT_ENUMERABLE)
    1.69 -    public volatile Object json;
    1.70 +    @Getter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE)
    1.71 +    public static Object getJSON(final Object self) {
    1.72 +        final Global global = Global.instanceFrom(self);
    1.73 +        if (global.json == LAZY_SENTINEL) {
    1.74 +            global.json = global.getBuiltinJSON();
    1.75 +        }
    1.76 +        return global.json;
    1.77 +    }
    1.78 +
    1.79 +    @Setter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE)
    1.80 +    public static void setJSON(final Object self, final Object value) {
    1.81 +        final Global global = Global.instanceFrom(self);
    1.82 +        global.json = value;
    1.83 +    }
    1.84 +
    1.85 +    private volatile Object json = LAZY_SENTINEL;
    1.86  
    1.87      /** Nashorn extension: global.JSAdapter */
    1.88 -    @Property(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE)
    1.89 -    public volatile Object jsadapter;
    1.90 +    @Getter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE)
    1.91 +    public static Object getJSAdapter(final Object self) {
    1.92 +        final Global global = Global.instanceFrom(self);
    1.93 +        if (global.jsadapter == LAZY_SENTINEL) {
    1.94 +            global.jsadapter = global.getBuiltinJSAdapter();
    1.95 +        }
    1.96 +        return global.jsadapter;
    1.97 +    }
    1.98 +
    1.99 +    @Setter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE)
   1.100 +    public static void setJSAdapter(final Object self, final Object value) {
   1.101 +        final Global global = Global.instanceFrom(self);
   1.102 +        global.jsadapter = value;
   1.103 +    }
   1.104 +
   1.105 +    private volatile Object jsadapter = LAZY_SENTINEL;
   1.106  
   1.107      /** ECMA 15.8 - The Math object */
   1.108      @Property(name = "Math", attributes = Attribute.NOT_ENUMERABLE)
   1.109 @@ -238,12 +299,40 @@
   1.110      public volatile Object error;
   1.111  
   1.112      /** EvalError object */
   1.113 -    @Property(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE)
   1.114 -    public volatile Object evalError;
   1.115 +    @Getter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE)
   1.116 +    public static Object getEvalError(final Object self) {
   1.117 +        final Global global = Global.instanceFrom(self);
   1.118 +        if (global.evalError == LAZY_SENTINEL) {
   1.119 +            global.evalError = global.getBuiltinEvalError();
   1.120 +        }
   1.121 +        return global.evalError;
   1.122 +    }
   1.123 +
   1.124 +    @Setter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE)
   1.125 +    public static void setEvalError(final Object self, final Object value) {
   1.126 +        final Global global = Global.instanceFrom(self);
   1.127 +        global.evalError = value;
   1.128 +    }
   1.129 +
   1.130 +    private volatile Object evalError = LAZY_SENTINEL;
   1.131  
   1.132      /** RangeError object */
   1.133 -    @Property(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE)
   1.134 -    public volatile Object rangeError;
   1.135 +    @Getter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE)
   1.136 +    public static Object getRangeError(final Object self) {
   1.137 +        final Global global = Global.instanceFrom(self);
   1.138 +        if (global.rangeError == LAZY_SENTINEL) {
   1.139 +            global.rangeError = global.getBuiltinRangeError();
   1.140 +        }
   1.141 +        return global.rangeError;
   1.142 +    }
   1.143 +
   1.144 +    @Setter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE)
   1.145 +    public static void setRangeError(final Object self, final Object value) {
   1.146 +        final Global global = Global.instanceFrom(self);
   1.147 +        global.rangeError = value;
   1.148 +    }
   1.149 +
   1.150 +    private volatile Object rangeError = LAZY_SENTINEL;
   1.151  
   1.152      /** ReferenceError object */
   1.153      @Property(name = "ReferenceError", attributes = Attribute.NOT_ENUMERABLE)
   1.154 @@ -258,52 +347,220 @@
   1.155      public volatile Object typeError;
   1.156  
   1.157      /** URIError object */
   1.158 -    @Property(name = "URIError", attributes = Attribute.NOT_ENUMERABLE)
   1.159 -    public volatile Object uriError;
   1.160 +    @Getter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE)
   1.161 +    public static Object getURIError(final Object self) {
   1.162 +        final Global global = Global.instanceFrom(self);
   1.163 +        if (global.uriError == LAZY_SENTINEL) {
   1.164 +            global.uriError = global.getBuiltinURIError();
   1.165 +        }
   1.166 +        return global.uriError;
   1.167 +    }
   1.168 +
   1.169 +    @Setter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE)
   1.170 +    public static void setURIError(final Object self, final Object value) {
   1.171 +        final Global global = Global.instanceFrom(self);
   1.172 +        global.uriError = value;
   1.173 +    }
   1.174 +
   1.175 +    private volatile Object uriError = LAZY_SENTINEL;
   1.176  
   1.177      /** ArrayBuffer object */
   1.178 -    @Property(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE)
   1.179 -    public volatile Object arrayBuffer;
   1.180 +    @Getter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE)
   1.181 +    public static Object getArrayBuffer(final Object self) {
   1.182 +        final Global global = Global.instanceFrom(self);
   1.183 +        if (global.arrayBuffer == LAZY_SENTINEL) {
   1.184 +            global.arrayBuffer = global.getBuiltinArrayBuffer();
   1.185 +        }
   1.186 +        return global.arrayBuffer;
   1.187 +    }
   1.188 +
   1.189 +    @Setter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE)
   1.190 +    public static void setArrayBuffer(final Object self, final Object value) {
   1.191 +        final Global global = Global.instanceFrom(self);
   1.192 +        global.arrayBuffer = value;
   1.193 +    }
   1.194 +
   1.195 +    private volatile Object arrayBuffer;
   1.196  
   1.197      /** DataView object */
   1.198 -    @Property(name = "DataView", attributes = Attribute.NOT_ENUMERABLE)
   1.199 -    public volatile Object dataView;
   1.200 +    @Getter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE)
   1.201 +    public static Object getDataView(final Object self) {
   1.202 +        final Global global = Global.instanceFrom(self);
   1.203 +        if (global.dataView == LAZY_SENTINEL) {
   1.204 +            global.dataView = global.getBuiltinDataView();
   1.205 +        }
   1.206 +        return global.dataView;
   1.207 +    }
   1.208 +
   1.209 +    @Setter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE)
   1.210 +    public static void setDataView(final Object self, final Object value) {
   1.211 +        final Global global = Global.instanceFrom(self);
   1.212 +        global.dataView = value;
   1.213 +    }
   1.214 +
   1.215 +    private volatile Object dataView;
   1.216  
   1.217      /** TypedArray (int8) */
   1.218 -    @Property(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE)
   1.219 -    public volatile Object int8Array;
   1.220 +    @Getter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE)
   1.221 +    public static Object getInt8Array(final Object self) {
   1.222 +        final Global global = Global.instanceFrom(self);
   1.223 +        if (global.int8Array == LAZY_SENTINEL) {
   1.224 +            global.int8Array = global.getBuiltinInt8Array();
   1.225 +        }
   1.226 +        return global.int8Array;
   1.227 +    }
   1.228 +
   1.229 +    @Setter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE)
   1.230 +    public static void setInt8Array(final Object self, final Object value) {
   1.231 +        final Global global = Global.instanceFrom(self);
   1.232 +        global.int8Array = value;
   1.233 +    }
   1.234 +
   1.235 +    private volatile Object int8Array;
   1.236  
   1.237      /** TypedArray (uint8) */
   1.238 -    @Property(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE)
   1.239 -    public volatile Object uint8Array;
   1.240 +    @Getter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE)
   1.241 +    public static Object getUint8Array(final Object self) {
   1.242 +        final Global global = Global.instanceFrom(self);
   1.243 +        if (global.uint8Array == LAZY_SENTINEL) {
   1.244 +            global.uint8Array = global.getBuiltinUint8Array();
   1.245 +        }
   1.246 +        return global.uint8Array;
   1.247 +    }
   1.248 +
   1.249 +    @Setter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE)
   1.250 +    public static void setUint8Array(final Object self, final Object value) {
   1.251 +        final Global global = Global.instanceFrom(self);
   1.252 +        global.uint8Array = value;
   1.253 +    }
   1.254 +
   1.255 +    private volatile Object uint8Array;
   1.256  
   1.257      /** TypedArray (uint8) - Clamped */
   1.258 -    @Property(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE)
   1.259 -    public volatile Object uint8ClampedArray;
   1.260 +    @Getter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE)
   1.261 +    public static Object getUint8ClampedArray(final Object self) {
   1.262 +        final Global global = Global.instanceFrom(self);
   1.263 +        if (global.uint8ClampedArray == LAZY_SENTINEL) {
   1.264 +            global.uint8ClampedArray = global.getBuiltinUint8ClampedArray();
   1.265 +        }
   1.266 +        return global.uint8ClampedArray;
   1.267 +    }
   1.268 +
   1.269 +    @Setter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE)
   1.270 +    public static void setUint8ClampedArray(final Object self, final Object value) {
   1.271 +        final Global global = Global.instanceFrom(self);
   1.272 +        global.uint8ClampedArray = value;
   1.273 +    }
   1.274 +
   1.275 +    private volatile Object uint8ClampedArray;
   1.276  
   1.277      /** TypedArray (int16) */
   1.278 -    @Property(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE)
   1.279 -    public volatile Object int16Array;
   1.280 +    @Getter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE)
   1.281 +    public static Object getInt16Array(final Object self) {
   1.282 +        final Global global = Global.instanceFrom(self);
   1.283 +        if (global.int16Array == LAZY_SENTINEL) {
   1.284 +            global.int16Array = global.getBuiltinInt16Array();
   1.285 +        }
   1.286 +        return global.int16Array;
   1.287 +    }
   1.288 +
   1.289 +    @Setter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE)
   1.290 +    public static void setInt16Array(final Object self, final Object value) {
   1.291 +        final Global global = Global.instanceFrom(self);
   1.292 +        global.int16Array = value;
   1.293 +    }
   1.294 +
   1.295 +    private volatile Object int16Array;
   1.296  
   1.297      /** TypedArray (uint16) */
   1.298 -    @Property(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE)
   1.299 -    public volatile Object uint16Array;
   1.300 +    @Getter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE)
   1.301 +    public static Object getUint16Array(final Object self) {
   1.302 +        final Global global = Global.instanceFrom(self);
   1.303 +        if (global.uint16Array == LAZY_SENTINEL) {
   1.304 +            global.uint16Array = global.getBuiltinUint16Array();
   1.305 +        }
   1.306 +        return global.uint16Array;
   1.307 +    }
   1.308 +
   1.309 +    @Setter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE)
   1.310 +    public static void setUint16Array(final Object self, final Object value) {
   1.311 +        final Global global = Global.instanceFrom(self);
   1.312 +        global.uint16Array = value;
   1.313 +    }
   1.314 +
   1.315 +    private volatile Object uint16Array;
   1.316  
   1.317      /** TypedArray (int32) */
   1.318 -    @Property(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE)
   1.319 -    public volatile Object int32Array;
   1.320 +    @Getter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE)
   1.321 +    public static Object getInt32Array(final Object self) {
   1.322 +        final Global global = Global.instanceFrom(self);
   1.323 +        if (global.int32Array == LAZY_SENTINEL) {
   1.324 +            global.int32Array = global.getBuiltinInt32Array();
   1.325 +        }
   1.326 +        return global.int32Array;
   1.327 +    }
   1.328 +
   1.329 +    @Setter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE)
   1.330 +    public static void setInt32Array(final Object self, final Object value) {
   1.331 +        final Global global = Global.instanceFrom(self);
   1.332 +        global.int32Array = value;
   1.333 +    }
   1.334 +
   1.335 +    private volatile Object int32Array;
   1.336  
   1.337      /** TypedArray (uint32) */
   1.338 -    @Property(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE)
   1.339 -    public volatile Object uint32Array;
   1.340 +    @Getter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE)
   1.341 +    public static Object getUint32Array(final Object self) {
   1.342 +        final Global global = Global.instanceFrom(self);
   1.343 +        if (global.uint32Array == LAZY_SENTINEL) {
   1.344 +            global.uint32Array = global.getBuiltinUint32Array();
   1.345 +        }
   1.346 +        return global.uint32Array;
   1.347 +    }
   1.348 +
   1.349 +    @Setter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE)
   1.350 +    public static void setUint32Array(final Object self, final Object value) {
   1.351 +        final Global global = Global.instanceFrom(self);
   1.352 +        global.uint32Array = value;
   1.353 +    }
   1.354 +
   1.355 +    private volatile Object uint32Array;
   1.356  
   1.357      /** TypedArray (float32) */
   1.358 -    @Property(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE)
   1.359 -    public volatile Object float32Array;
   1.360 +    @Getter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE)
   1.361 +    public static Object getFloat32Array(final Object self) {
   1.362 +        final Global global = Global.instanceFrom(self);
   1.363 +        if (global.float32Array == LAZY_SENTINEL) {
   1.364 +            global.float32Array = global.getBuiltinFloat32Array();
   1.365 +        }
   1.366 +        return global.float32Array;
   1.367 +    }
   1.368 +
   1.369 +    @Setter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE)
   1.370 +    public static void setFloat32Array(final Object self, final Object value) {
   1.371 +        final Global global = Global.instanceFrom(self);
   1.372 +        global.float32Array = value;
   1.373 +    }
   1.374 +
   1.375 +    private volatile Object float32Array;
   1.376  
   1.377      /** TypedArray (float64) */
   1.378 -    @Property(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE)
   1.379 -    public volatile Object float64Array;
   1.380 +    @Getter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE)
   1.381 +    public static Object getFloat64Array(final Object self) {
   1.382 +        final Global global = Global.instanceFrom(self);
   1.383 +        if (global.float64Array == LAZY_SENTINEL) {
   1.384 +            global.float64Array = global.getBuiltinFloat64Array();
   1.385 +        }
   1.386 +        return global.float64Array;
   1.387 +    }
   1.388 +
   1.389 +    @Setter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE)
   1.390 +    public static void setFloat64Array(final Object self, final Object value) {
   1.391 +        final Global global = Global.instanceFrom(self);
   1.392 +        global.float64Array = value;
   1.393 +    }
   1.394 +
   1.395 +    private volatile Object float64Array;
   1.396  
   1.397      /** Nashorn extension: Java access - global.Packages */
   1.398      @Property(name = "Packages", attributes = Attribute.NOT_ENUMERABLE)
   1.399 @@ -334,12 +591,40 @@
   1.400      public volatile Object org;
   1.401  
   1.402      /** Nashorn extension: Java access - global.javaImporter */
   1.403 -    @Property(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE)
   1.404 -    public volatile Object javaImporter;
   1.405 +    @Getter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE)
   1.406 +    public static Object getJavaImporter(final Object self) {
   1.407 +        final Global global = Global.instanceFrom(self);
   1.408 +        if (global.javaImporter == LAZY_SENTINEL) {
   1.409 +            global.javaImporter = global.getBuiltinJavaImporter();
   1.410 +        }
   1.411 +        return global.javaImporter;
   1.412 +    }
   1.413 +
   1.414 +    @Setter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE)
   1.415 +    public static void setJavaImporter(final Object self, final Object value) {
   1.416 +        final Global global = Global.instanceFrom(self);
   1.417 +        global.javaImporter = value;
   1.418 +    }
   1.419 +
   1.420 +    private volatile Object javaImporter;
   1.421  
   1.422      /** Nashorn extension: global.Java Object constructor. */
   1.423 -    @Property(name = "Java", attributes = Attribute.NOT_ENUMERABLE)
   1.424 -    public volatile Object javaApi;
   1.425 +    @Getter(name = "Java", attributes = Attribute.NOT_ENUMERABLE)
   1.426 +    public static Object getJavaApi(final Object self) {
   1.427 +        final Global global = Global.instanceFrom(self);
   1.428 +        if (global.javaApi == LAZY_SENTINEL) {
   1.429 +            global.javaApi = global.getBuiltinJavaApi();
   1.430 +        }
   1.431 +        return global.javaApi;
   1.432 +    }
   1.433 +
   1.434 +    @Setter(name = "Java", attributes = Attribute.NOT_ENUMERABLE)
   1.435 +    public static void setJavaApi(final Object self, final Object value) {
   1.436 +        final Global global = Global.instanceFrom(self);
   1.437 +        global.javaApi = value;
   1.438 +    }
   1.439 +
   1.440 +    private volatile Object javaApi;
   1.441  
   1.442      /** Nashorn extension: current script's file name */
   1.443      @Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
   1.444 @@ -353,11 +638,19 @@
   1.445      @Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
   1.446      public final Object __LINE__ = LOCATION_PROPERTY_PLACEHOLDER;
   1.447  
   1.448 +    private volatile NativeDate DEFAULT_DATE;
   1.449 +
   1.450      /** Used as Date.prototype's default value */
   1.451 -    public NativeDate   DEFAULT_DATE;
   1.452 +    NativeDate getDefaultDate() {
   1.453 +        return DEFAULT_DATE;
   1.454 +    }
   1.455 +
   1.456 +    private volatile NativeRegExp DEFAULT_REGEXP;
   1.457  
   1.458      /** Used as RegExp.prototype's default value */
   1.459 -    public NativeRegExp DEFAULT_REGEXP;
   1.460 +    NativeRegExp getDefaultRegExp() {
   1.461 +        return DEFAULT_REGEXP;
   1.462 +    }
   1.463  
   1.464      /*
   1.465       * Built-in constructor objects: Even if user changes dynamic values of
   1.466 @@ -1035,7 +1328,7 @@
   1.467  
   1.468      /**
   1.469       * Get the builtin Object prototype.
   1.470 -      * @return the object prototype.
   1.471 +     * @return the object prototype.
   1.472       */
   1.473      public ScriptObject getObjectPrototype() {
   1.474          return ScriptFunction.getPrototype(builtinObject);
   1.475 @@ -1058,11 +1351,11 @@
   1.476      }
   1.477  
   1.478      ScriptObject getDatePrototype() {
   1.479 -        return ScriptFunction.getPrototype(builtinDate);
   1.480 +        return ScriptFunction.getPrototype(getBuiltinDate());
   1.481      }
   1.482  
   1.483      ScriptObject getRegExpPrototype() {
   1.484 -        return ScriptFunction.getPrototype(builtinRegExp);
   1.485 +        return ScriptFunction.getPrototype(getBuiltinRegExp());
   1.486      }
   1.487  
   1.488      ScriptObject getStringPrototype() {
   1.489 @@ -1074,11 +1367,11 @@
   1.490      }
   1.491  
   1.492      ScriptObject getEvalErrorPrototype() {
   1.493 -        return ScriptFunction.getPrototype(builtinEvalError);
   1.494 +        return ScriptFunction.getPrototype(getBuiltinEvalError());
   1.495      }
   1.496  
   1.497      ScriptObject getRangeErrorPrototype() {
   1.498 -        return ScriptFunction.getPrototype(builtinRangeError);
   1.499 +        return ScriptFunction.getPrototype(getBuiltinRangeError());
   1.500      }
   1.501  
   1.502      ScriptObject getReferenceErrorPrototype() {
   1.503 @@ -1094,59 +1387,136 @@
   1.504      }
   1.505  
   1.506      ScriptObject getURIErrorPrototype() {
   1.507 -        return ScriptFunction.getPrototype(builtinURIError);
   1.508 +        return ScriptFunction.getPrototype(getBuiltinURIError());
   1.509      }
   1.510  
   1.511      ScriptObject getJavaImporterPrototype() {
   1.512 -        return ScriptFunction.getPrototype(builtinJavaImporter);
   1.513 +        return ScriptFunction.getPrototype(getBuiltinJavaImporter());
   1.514      }
   1.515  
   1.516      ScriptObject getJSAdapterPrototype() {
   1.517 -        return ScriptFunction.getPrototype(builtinJSAdapter);
   1.518 +        return ScriptFunction.getPrototype(getBuiltinJSAdapter());
   1.519      }
   1.520  
   1.521 +    private synchronized ScriptFunction getBuiltinArrayBuffer() {
   1.522 +        if (this.builtinArrayBuffer == null) {
   1.523 +            this.builtinArrayBuffer = initConstructorAndSwitchPoint("ArrayBuffer", ScriptFunction.class);
   1.524 +        }
   1.525 +        return this.builtinArrayBuffer;
   1.526 +    }
   1.527 +
   1.528      ScriptObject getArrayBufferPrototype() {
   1.529 -        return ScriptFunction.getPrototype(builtinArrayBuffer);
   1.530 +        return ScriptFunction.getPrototype(getBuiltinArrayBuffer());
   1.531      }
   1.532  
   1.533 +    private synchronized ScriptFunction getBuiltinDataView() {
   1.534 +        if (this.builtinDataView == null) {
   1.535 +            this.builtinDataView = initConstructorAndSwitchPoint("DataView", ScriptFunction.class);
   1.536 +        }
   1.537 +        return this.builtinDataView;
   1.538 +    }
   1.539 +
   1.540      ScriptObject getDataViewPrototype() {
   1.541 -        return ScriptFunction.getPrototype(builtinDataView);
   1.542 +        return ScriptFunction.getPrototype(getBuiltinDataView());
   1.543      }
   1.544  
   1.545 +    private synchronized ScriptFunction getBuiltinInt8Array() {
   1.546 +        if (this.builtinInt8Array == null) {
   1.547 +            this.builtinInt8Array = initConstructorAndSwitchPoint("Int8Array", ScriptFunction.class);
   1.548 +        }
   1.549 +        return this.builtinInt8Array;
   1.550 +    }
   1.551 +
   1.552      ScriptObject getInt8ArrayPrototype() {
   1.553 -        return ScriptFunction.getPrototype(builtinInt8Array);
   1.554 +        return ScriptFunction.getPrototype(getBuiltinInt8Array());
   1.555      }
   1.556  
   1.557 +    private synchronized ScriptFunction getBuiltinUint8Array() {
   1.558 +        if (this.builtinUint8Array == null) {
   1.559 +            this.builtinUint8Array = initConstructorAndSwitchPoint("Uint8Array", ScriptFunction.class);
   1.560 +        }
   1.561 +        return this.builtinUint8Array;
   1.562 +    }
   1.563 +
   1.564      ScriptObject getUint8ArrayPrototype() {
   1.565 -        return ScriptFunction.getPrototype(builtinUint8Array);
   1.566 +        return ScriptFunction.getPrototype(getBuiltinUint8Array());
   1.567      }
   1.568  
   1.569 +    private synchronized ScriptFunction getBuiltinUint8ClampedArray() {
   1.570 +        if (this.builtinUint8ClampedArray == null) {
   1.571 +            this.builtinUint8ClampedArray = initConstructorAndSwitchPoint("Uint8ClampedArray", ScriptFunction.class);
   1.572 +        }
   1.573 +        return this.builtinUint8ClampedArray;
   1.574 +    }
   1.575 +
   1.576      ScriptObject getUint8ClampedArrayPrototype() {
   1.577 -        return ScriptFunction.getPrototype(builtinUint8ClampedArray);
   1.578 +        return ScriptFunction.getPrototype(getBuiltinUint8ClampedArray());
   1.579      }
   1.580  
   1.581 +    private synchronized ScriptFunction getBuiltinInt16Array() {
   1.582 +        if (this.builtinInt16Array == null) {
   1.583 +            this.builtinInt16Array = initConstructorAndSwitchPoint("Int16Array", ScriptFunction.class);
   1.584 +        }
   1.585 +        return this.builtinInt16Array;
   1.586 +    }
   1.587 +
   1.588      ScriptObject getInt16ArrayPrototype() {
   1.589 -        return ScriptFunction.getPrototype(builtinInt16Array);
   1.590 +        return ScriptFunction.getPrototype(getBuiltinInt16Array());
   1.591      }
   1.592  
   1.593 +    private synchronized ScriptFunction getBuiltinUint16Array() {
   1.594 +        if (this.builtinUint16Array == null) {
   1.595 +            this.builtinUint16Array = initConstructorAndSwitchPoint("Uint16Array", ScriptFunction.class);
   1.596 +        }
   1.597 +        return this.builtinUint16Array;
   1.598 +    }
   1.599 +
   1.600      ScriptObject getUint16ArrayPrototype() {
   1.601 -        return ScriptFunction.getPrototype(builtinUint16Array);
   1.602 +        return ScriptFunction.getPrototype(getBuiltinUint16Array());
   1.603      }
   1.604  
   1.605 +    private synchronized ScriptFunction getBuiltinInt32Array() {
   1.606 +        if (this.builtinInt32Array == null) {
   1.607 +            this.builtinInt32Array = initConstructorAndSwitchPoint("Int32Array", ScriptFunction.class);
   1.608 +        }
   1.609 +        return this.builtinInt32Array;
   1.610 +    }
   1.611 +
   1.612      ScriptObject getInt32ArrayPrototype() {
   1.613 -        return ScriptFunction.getPrototype(builtinInt32Array);
   1.614 +        return ScriptFunction.getPrototype(getBuiltinInt32Array());
   1.615      }
   1.616  
   1.617 +    private synchronized ScriptFunction getBuiltinUint32Array() {
   1.618 +        if (this.builtinUint32Array == null) {
   1.619 +            this.builtinUint32Array = initConstructorAndSwitchPoint("Uint32Array", ScriptFunction.class);
   1.620 +        }
   1.621 +        return this.builtinUint32Array;
   1.622 +    }
   1.623 +
   1.624      ScriptObject getUint32ArrayPrototype() {
   1.625 -        return ScriptFunction.getPrototype(builtinUint32Array);
   1.626 +        return ScriptFunction.getPrototype(getBuiltinUint32Array());
   1.627      }
   1.628  
   1.629 +    private synchronized ScriptFunction getBuiltinFloat32Array() {
   1.630 +        if (this.builtinFloat32Array == null) {
   1.631 +            this.builtinFloat32Array = initConstructorAndSwitchPoint("Float32Array", ScriptFunction.class);
   1.632 +        }
   1.633 +        return this.builtinFloat32Array;
   1.634 +    }
   1.635 +
   1.636      ScriptObject getFloat32ArrayPrototype() {
   1.637 -        return ScriptFunction.getPrototype(builtinFloat32Array);
   1.638 +        return ScriptFunction.getPrototype(getBuiltinFloat32Array());
   1.639      }
   1.640  
   1.641 +    private synchronized ScriptFunction getBuiltinFloat64Array() {
   1.642 +        if (this.builtinFloat64Array == null) {
   1.643 +            this.builtinFloat64Array = initConstructorAndSwitchPoint("Float64Array", ScriptFunction.class);
   1.644 +        }
   1.645 +        return this.builtinFloat64Array;
   1.646 +    }
   1.647 +
   1.648      ScriptObject getFloat64ArrayPrototype() {
   1.649 -        return ScriptFunction.getPrototype(builtinFloat64Array);
   1.650 +        return ScriptFunction.getPrototype(getBuiltinFloat64Array());
   1.651      }
   1.652  
   1.653      private ScriptFunction getBuiltinArray() {
   1.654 @@ -1181,8 +1551,14 @@
   1.655          return instance._boolean == instance.getBuiltinBoolean();
   1.656      }
   1.657  
   1.658 -    private ScriptFunction getBuiltinDate() {
   1.659 -        return builtinDate;
   1.660 +    private synchronized ScriptFunction getBuiltinDate() {
   1.661 +        if (this.builtinDate == null) {
   1.662 +            this.builtinDate = initConstructorAndSwitchPoint("Date", ScriptFunction.class);
   1.663 +            final ScriptObject dateProto = ScriptFunction.getPrototype(builtinDate);
   1.664 +            // initialize default date
   1.665 +            this.DEFAULT_DATE = new NativeDate(NaN, dateProto);
   1.666 +        }
   1.667 +        return this.builtinDate;
   1.668      }
   1.669  
   1.670      /**
   1.671 @@ -1192,7 +1568,7 @@
   1.672       */
   1.673      public static boolean isBuiltinDate() {
   1.674          final Global instance = Global.instance();
   1.675 -        return instance.date == instance.getBuiltinDate();
   1.676 +        return instance.date == LAZY_SENTINEL || instance.date == instance.getBuiltinDate();
   1.677      }
   1.678  
   1.679      private ScriptFunction getBuiltinError() {
   1.680 @@ -1209,8 +1585,11 @@
   1.681          return instance.error == instance.getBuiltinError();
   1.682      }
   1.683  
   1.684 -    private ScriptFunction getBuiltinEvalError() {
   1.685 -        return builtinEvalError;
   1.686 +    private synchronized ScriptFunction getBuiltinEvalError() {
   1.687 +        if (this.builtinEvalError == null) {
   1.688 +            this.builtinEvalError = initErrorSubtype("EvalError", getErrorPrototype());
   1.689 +        }
   1.690 +        return this.builtinEvalError;
   1.691      }
   1.692  
   1.693      /**
   1.694 @@ -1220,7 +1599,7 @@
   1.695       */
   1.696      public static boolean isBuiltinEvalError() {
   1.697          final Global instance = Global.instance();
   1.698 -        return instance.evalError == instance.getBuiltinEvalError();
   1.699 +        return instance.evalError == LAZY_SENTINEL || instance.evalError == instance.getBuiltinEvalError();
   1.700      }
   1.701  
   1.702      private ScriptFunction getBuiltinFunction() {
   1.703 @@ -1271,7 +1650,10 @@
   1.704          return isBuiltinFunctionProperty("call");
   1.705      }
   1.706  
   1.707 -    private ScriptFunction getBuiltinJSAdapter() {
   1.708 +    private synchronized ScriptFunction getBuiltinJSAdapter() {
   1.709 +        if (this.builtinJSAdapter == null) {
   1.710 +            this.builtinJSAdapter = initConstructorAndSwitchPoint("JSAdapter", ScriptFunction.class);
   1.711 +        }
   1.712          return builtinJSAdapter;
   1.713      }
   1.714  
   1.715 @@ -1282,11 +1664,14 @@
   1.716       */
   1.717      public static boolean isBuiltinJSAdapter() {
   1.718          final Global instance = Global.instance();
   1.719 -        return instance.jsadapter == instance.getBuiltinJSAdapter();
   1.720 +        return instance.jsadapter == LAZY_SENTINEL || instance.jsadapter == instance.getBuiltinJSAdapter();
   1.721      }
   1.722  
   1.723 -    private ScriptObject getBuiltinJSON() {
   1.724 -        return builtinJSON;
   1.725 +    private synchronized ScriptObject getBuiltinJSON() {
   1.726 +        if (this.builtinJSON == null) {
   1.727 +            this.builtinJSON = initConstructorAndSwitchPoint("JSON", ScriptObject.class);
   1.728 +        }
   1.729 +        return this.builtinJSON;
   1.730      }
   1.731  
   1.732      /**
   1.733 @@ -1296,7 +1681,7 @@
   1.734       */
   1.735      public static boolean isBuiltinJSON() {
   1.736          final Global instance = Global.instance();
   1.737 -        return instance.json == instance.getBuiltinJSON();
   1.738 +        return instance.json == LAZY_SENTINEL || instance.json == instance.getBuiltinJSON();
   1.739      }
   1.740  
   1.741      private ScriptObject getBuiltinJava() {
   1.742 @@ -1327,8 +1712,18 @@
   1.743          return instance.javax == instance.getBuiltinJavax();
   1.744      }
   1.745  
   1.746 -    private ScriptObject getBuiltinJavaImporter() {
   1.747 -        return builtinJavaImporter;
   1.748 +    private synchronized ScriptFunction getBuiltinJavaImporter() {
   1.749 +        if (this.builtinJavaImporter == null) {
   1.750 +            this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class);
   1.751 +        }
   1.752 +        return this.builtinJavaImporter;
   1.753 +    }
   1.754 +
   1.755 +    private synchronized ScriptObject getBuiltinJavaApi() {
   1.756 +        if (this.builtinJavaApi == null) {
   1.757 +            this.builtinJavaApi = initConstructor("Java", ScriptObject.class);
   1.758 +        }
   1.759 +        return this.builtinJavaApi;
   1.760      }
   1.761  
   1.762      /**
   1.763 @@ -1338,11 +1733,7 @@
   1.764       */
   1.765      public static boolean isBuiltinJavaImporter() {
   1.766          final Global instance = Global.instance();
   1.767 -        return instance.javaImporter == instance.getBuiltinJavaImporter();
   1.768 -    }
   1.769 -
   1.770 -    private ScriptObject getBuiltinMath() {
   1.771 -        return builtinMath;
   1.772 +        return instance.javaImporter == LAZY_SENTINEL || instance.javaImporter == instance.getBuiltinJavaImporter();
   1.773      }
   1.774  
   1.775      /**
   1.776 @@ -1352,7 +1743,7 @@
   1.777       */
   1.778      public static boolean isBuiltinMath() {
   1.779          final Global instance = Global.instance();
   1.780 -        return instance.math == instance.getBuiltinMath();
   1.781 +        return instance.math == instance.builtinMath;
   1.782      }
   1.783  
   1.784      private ScriptFunction getBuiltinNumber() {
   1.785 @@ -1397,7 +1788,10 @@
   1.786          return instance.packages == instance.getBuiltinPackages();
   1.787      }
   1.788  
   1.789 -    private ScriptFunction getBuiltinRangeError() {
   1.790 +    private synchronized ScriptFunction getBuiltinRangeError() {
   1.791 +        if (this.builtinRangeError == null) {
   1.792 +            this.builtinRangeError = initErrorSubtype("RangeError", getErrorPrototype());
   1.793 +        }
   1.794          return builtinRangeError;
   1.795      }
   1.796  
   1.797 @@ -1408,10 +1802,10 @@
   1.798       */
   1.799      public static boolean isBuiltinRangeError() {
   1.800          final Global instance = Global.instance();
   1.801 -        return instance.rangeError == instance.getBuiltinRangeError();
   1.802 +        return instance.rangeError == LAZY_SENTINEL || instance.rangeError == instance.getBuiltinRangeError();
   1.803      }
   1.804  
   1.805 -    private ScriptFunction getBuiltinReferenceError() {
   1.806 +    private synchronized ScriptFunction getBuiltinReferenceError() {
   1.807          return builtinReferenceError;
   1.808      }
   1.809  
   1.810 @@ -1425,7 +1819,16 @@
   1.811          return instance.referenceError == instance.getBuiltinReferenceError();
   1.812      }
   1.813  
   1.814 -    private ScriptFunction getBuiltinRegExp() {
   1.815 +    private synchronized ScriptFunction getBuiltinRegExp() {
   1.816 +        if (this.builtinRegExp == null) {
   1.817 +            this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
   1.818 +            final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp);
   1.819 +            // initialize default regexp object
   1.820 +            this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto);
   1.821 +            // RegExp.prototype should behave like a RegExp object. So copy the
   1.822 +            // properties.
   1.823 +            regExpProto.addBoundProperties(DEFAULT_REGEXP);
   1.824 +        }
   1.825          return builtinRegExp;
   1.826      }
   1.827  
   1.828 @@ -1436,7 +1839,7 @@
   1.829       */
   1.830      public static boolean isBuiltinRegExp() {
   1.831          final Global instance = Global.instance();
   1.832 -        return instance.regexp == instance.getBuiltinRegExp();
   1.833 +        return instance.regexp == LAZY_SENTINEL || instance.regexp == instance.getBuiltinRegExp();
   1.834      }
   1.835  
   1.836      private ScriptFunction getBuiltinString() {
   1.837 @@ -1481,8 +1884,11 @@
   1.838          return instance.typeError == instance.getBuiltinTypeError();
   1.839      }
   1.840  
   1.841 -    private ScriptFunction getBuiltinURIError() {
   1.842 -        return builtinURIError;
   1.843 +    private synchronized ScriptFunction getBuiltinURIError() {
   1.844 +        if (this.builtinURIError == null) {
   1.845 +            this.builtinURIError = initErrorSubtype("URIError", getErrorPrototype());
   1.846 +        }
   1.847 +        return this.builtinURIError;
   1.848      }
   1.849  
   1.850      /**
   1.851 @@ -1492,7 +1898,7 @@
   1.852       */
   1.853      public static boolean isBuiltinURIError() {
   1.854          final Global instance = Global.instance();
   1.855 -        return instance.uriError == instance.getBuiltinURIError();
   1.856 +        return instance.uriError == LAZY_SENTINEL || instance.uriError == instance.getBuiltinURIError();
   1.857      }
   1.858  
   1.859      @Override
   1.860 @@ -1905,13 +2311,9 @@
   1.861          // built-in constructors
   1.862          this.builtinArray     = initConstructorAndSwitchPoint("Array", ScriptFunction.class);
   1.863          this.builtinBoolean   = initConstructorAndSwitchPoint("Boolean", ScriptFunction.class);
   1.864 -        this.builtinDate      = initConstructorAndSwitchPoint("Date", ScriptFunction.class);
   1.865 -        this.builtinJSON      = initConstructorAndSwitchPoint("JSON", ScriptObject.class);
   1.866 -        this.builtinJSAdapter = initConstructorAndSwitchPoint("JSAdapter", ScriptFunction.class);
   1.867 +        this.builtinNumber    = initConstructorAndSwitchPoint("Number", ScriptFunction.class);
   1.868 +        this.builtinString    = initConstructorAndSwitchPoint("String", ScriptFunction.class);
   1.869          this.builtinMath      = initConstructorAndSwitchPoint("Math", ScriptObject.class);
   1.870 -        this.builtinNumber    = initConstructorAndSwitchPoint("Number", ScriptFunction.class);
   1.871 -        this.builtinRegExp    = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
   1.872 -        this.builtinString    = initConstructorAndSwitchPoint("String", ScriptFunction.class);
   1.873  
   1.874          // initialize String.prototype.length to 0
   1.875          // add String.prototype.length
   1.876 @@ -1922,26 +2324,28 @@
   1.877          final ScriptObject arrayPrototype = getArrayPrototype();
   1.878          arrayPrototype.setIsArray();
   1.879  
   1.880 -        this.DEFAULT_DATE = new NativeDate(Double.NaN, this);
   1.881 -
   1.882 -        // initialize default regexp object
   1.883 -        this.DEFAULT_REGEXP = new NativeRegExp("(?:)", this);
   1.884 -
   1.885 -        // RegExp.prototype should behave like a RegExp object. So copy the
   1.886 -        // properties.
   1.887 -        final ScriptObject regExpProto = getRegExpPrototype();
   1.888 -        regExpProto.addBoundProperties(DEFAULT_REGEXP);
   1.889 -
   1.890          // Error stuff
   1.891          initErrorObjects();
   1.892  
   1.893          // java access
   1.894          if (! env._no_java) {
   1.895 +            this.javaApi = LAZY_SENTINEL;
   1.896 +            this.javaImporter = LAZY_SENTINEL;
   1.897              initJavaAccess();
   1.898          }
   1.899  
   1.900          if (! env._no_typed_arrays) {
   1.901 -            initTypedArray();
   1.902 +            this.arrayBuffer       = LAZY_SENTINEL;
   1.903 +            this.dataView          = LAZY_SENTINEL;
   1.904 +            this.int8Array         = LAZY_SENTINEL;
   1.905 +            this.uint8Array        = LAZY_SENTINEL;
   1.906 +            this.uint8ClampedArray = LAZY_SENTINEL;
   1.907 +            this.int16Array        = LAZY_SENTINEL;
   1.908 +            this.uint16Array       = LAZY_SENTINEL;
   1.909 +            this.int32Array        = LAZY_SENTINEL;
   1.910 +            this.uint32Array       = LAZY_SENTINEL;
   1.911 +            this.float32Array      = LAZY_SENTINEL;
   1.912 +            this.float64Array      = LAZY_SENTINEL;
   1.913          }
   1.914  
   1.915          if (env._scripting) {
   1.916 @@ -2015,12 +2419,9 @@
   1.917  
   1.918          tagBuiltinProperties("Error", builtinError);
   1.919  
   1.920 -        this.builtinEvalError = initErrorSubtype("EvalError", errorProto);
   1.921 -        this.builtinRangeError = initErrorSubtype("RangeError", errorProto);
   1.922          this.builtinReferenceError = initErrorSubtype("ReferenceError", errorProto);
   1.923          this.builtinSyntaxError = initErrorSubtype("SyntaxError", errorProto);
   1.924          this.builtinTypeError = initErrorSubtype("TypeError", errorProto);
   1.925 -        this.builtinURIError = initErrorSubtype("URIError", errorProto);
   1.926      }
   1.927  
   1.928      private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) {
   1.929 @@ -2042,8 +2443,6 @@
   1.930          this.builtinJavafx = new NativeJavaPackage("javafx", objectProto);
   1.931          this.builtinJavax = new NativeJavaPackage("javax", objectProto);
   1.932          this.builtinOrg = new NativeJavaPackage("org", objectProto);
   1.933 -        this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class);
   1.934 -        this.builtinJavaApi = initConstructor("Java", ScriptObject.class);
   1.935      }
   1.936  
   1.937      private void initScripting(final ScriptEnvironment scriptEnv) {
   1.938 @@ -2095,60 +2494,25 @@
   1.939          }
   1.940      }
   1.941  
   1.942 -    private void initTypedArray() {
   1.943 -        this.builtinArrayBuffer       = initConstructorAndSwitchPoint("ArrayBuffer", ScriptFunction.class);
   1.944 -        this.builtinDataView          = initConstructorAndSwitchPoint("DataView", ScriptFunction.class);
   1.945 -        this.builtinInt8Array         = initConstructorAndSwitchPoint("Int8Array", ScriptFunction.class);
   1.946 -        this.builtinUint8Array        = initConstructorAndSwitchPoint("Uint8Array", ScriptFunction.class);
   1.947 -        this.builtinUint8ClampedArray = initConstructorAndSwitchPoint("Uint8ClampedArray", ScriptFunction.class);
   1.948 -        this.builtinInt16Array        = initConstructorAndSwitchPoint("Int16Array", ScriptFunction.class);
   1.949 -        this.builtinUint16Array       = initConstructorAndSwitchPoint("Uint16Array", ScriptFunction.class);
   1.950 -        this.builtinInt32Array        = initConstructorAndSwitchPoint("Int32Array", ScriptFunction.class);
   1.951 -        this.builtinUint32Array       = initConstructorAndSwitchPoint("Uint32Array", ScriptFunction.class);
   1.952 -        this.builtinFloat32Array      = initConstructorAndSwitchPoint("Float32Array", ScriptFunction.class);
   1.953 -        this.builtinFloat64Array      = initConstructorAndSwitchPoint("Float64Array", ScriptFunction.class);
   1.954 -
   1.955 -    }
   1.956 -
   1.957      private void copyBuiltins() {
   1.958          this.array             = this.builtinArray;
   1.959          this._boolean          = this.builtinBoolean;
   1.960 -        this.date              = this.builtinDate;
   1.961          this.error             = this.builtinError;
   1.962 -        this.evalError         = this.builtinEvalError;
   1.963          this.function          = this.builtinFunction;
   1.964 -        this.jsadapter         = this.builtinJSAdapter;
   1.965 -        this.json              = this.builtinJSON;
   1.966          this.com               = this.builtinCom;
   1.967          this.edu               = this.builtinEdu;
   1.968          this.java              = this.builtinJava;
   1.969          this.javafx            = this.builtinJavafx;
   1.970          this.javax             = this.builtinJavax;
   1.971          this.org               = this.builtinOrg;
   1.972 -        this.javaImporter      = this.builtinJavaImporter;
   1.973 -        this.javaApi           = this.builtinJavaApi;
   1.974          this.math              = this.builtinMath;
   1.975          this.number            = this.builtinNumber;
   1.976          this.object            = this.builtinObject;
   1.977          this.packages          = this.builtinPackages;
   1.978 -        this.rangeError        = this.builtinRangeError;
   1.979          this.referenceError    = this.builtinReferenceError;
   1.980 -        this.regexp            = this.builtinRegExp;
   1.981          this.string            = this.builtinString;
   1.982          this.syntaxError       = this.builtinSyntaxError;
   1.983          this.typeError         = this.builtinTypeError;
   1.984 -        this.uriError          = this.builtinURIError;
   1.985 -        this.arrayBuffer       = this.builtinArrayBuffer;
   1.986 -        this.dataView          = this.builtinDataView;
   1.987 -        this.int8Array         = this.builtinInt8Array;
   1.988 -        this.uint8Array        = this.builtinUint8Array;
   1.989 -        this.uint8ClampedArray = this.builtinUint8ClampedArray;
   1.990 -        this.int16Array        = this.builtinInt16Array;
   1.991 -        this.uint16Array       = this.builtinUint16Array;
   1.992 -        this.int32Array        = this.builtinInt32Array;
   1.993 -        this.uint32Array       = this.builtinUint32Array;
   1.994 -        this.float32Array      = this.builtinFloat32Array;
   1.995 -        this.float64Array      = this.builtinFloat64Array;
   1.996      }
   1.997  
   1.998      private void initDebug() {
     2.1 --- a/src/jdk/nashorn/internal/objects/NativeDate.java	Tue Mar 24 13:59:31 2015 +0530
     2.2 +++ b/src/jdk/nashorn/internal/objects/NativeDate.java	Wed Mar 25 14:36:22 2015 +0530
     2.3 @@ -121,6 +121,10 @@
     2.4          this.timezone = env._timezone;
     2.5      }
     2.6  
     2.7 +    NativeDate(final double time, final ScriptObject proto) {
     2.8 +        this(time, proto, $nasgenmap$);
     2.9 +    }
    2.10 +
    2.11      NativeDate(final double time, final Global global) {
    2.12          this(time, global.getDatePrototype(), $nasgenmap$);
    2.13      }
    2.14 @@ -1276,7 +1280,7 @@
    2.15          if (self instanceof NativeDate) {
    2.16              return (NativeDate)self;
    2.17          } else if (self != null && self == Global.instance().getDatePrototype()) {
    2.18 -            return Global.instance().DEFAULT_DATE;
    2.19 +            return Global.instance().getDefaultDate();
    2.20          } else {
    2.21              throw typeError("not.a.date", ScriptRuntime.safeToString(self));
    2.22          }
     3.1 --- a/src/jdk/nashorn/internal/objects/NativeRegExp.java	Tue Mar 24 13:59:31 2015 +0530
     3.2 +++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java	Wed Mar 25 14:36:22 2015 +0530
     3.3 @@ -78,8 +78,8 @@
     3.4          this.globalObject = global;
     3.5      }
     3.6  
     3.7 -    NativeRegExp(final String input, final String flagString, final Global global) {
     3.8 -        this(global);
     3.9 +    NativeRegExp(final String input, final String flagString, final Global global, final ScriptObject proto) {
    3.10 +        super(proto, $nasgenmap$);
    3.11          try {
    3.12              this.regexp = RegExpFactory.create(input, flagString);
    3.13          } catch (final ParserException e) {
    3.14 @@ -87,8 +87,12 @@
    3.15              e.throwAsEcmaException();
    3.16              throw new AssertionError(); //guard against null warnings below
    3.17          }
    3.18 +        this.globalObject = global;
    3.19 +        this.setLastIndex(0);
    3.20 +    }
    3.21  
    3.22 -        this.setLastIndex(0);
    3.23 +    NativeRegExp(final String input, final String flagString, final Global global) {
    3.24 +        this(input, flagString, global, global.getRegExpPrototype());
    3.25      }
    3.26  
    3.27      NativeRegExp(final String input, final String flagString) {
    3.28 @@ -928,7 +932,7 @@
    3.29          if (self instanceof NativeRegExp) {
    3.30              return (NativeRegExp)self;
    3.31          } else if (self != null && self == Global.instance().getRegExpPrototype()) {
    3.32 -            return Global.instance().DEFAULT_REGEXP;
    3.33 +            return Global.instance().getDefaultRegExp();
    3.34          } else {
    3.35              throw typeError("not.a.regexp", ScriptRuntime.safeToString(self));
    3.36          }

mercurial