src/jdk/nashorn/internal/runtime/ScriptObject.java

changeset 541
c3b6ce7b74bf
parent 538
e43ab4062636
child 620
8c617a092d68
     1.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java	Thu Sep 05 21:17:06 2013 +0530
     1.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java	Mon Sep 09 20:10:41 2013 +0530
     1.3 @@ -120,9 +120,6 @@
     1.4      /** objects proto. */
     1.5      private ScriptObject proto;
     1.6  
     1.7 -    /** Context of the object, lazily cached. */
     1.8 -    private Context context;
     1.9 -
    1.10      /** Object flags. */
    1.11      private int flags;
    1.12  
    1.13 @@ -1043,40 +1040,11 @@
    1.14      }
    1.15  
    1.16      /**
    1.17 -     * Return true if the script object context is strict
    1.18 -     * @return true if strict context
    1.19 -     */
    1.20 -    public final boolean isStrictContext() {
    1.21 -        return getContext()._strict;
    1.22 -    }
    1.23 -
    1.24 -    /**
    1.25 -     * Checks if this object belongs to the given context
    1.26 -     * @param ctx context to check against
    1.27 -     * @return true if this object belongs to the given context
    1.28 -     */
    1.29 -    public final boolean isOfContext(final Context ctx) {
    1.30 -        return context == ctx;
    1.31 -    }
    1.32 -
    1.33 -    /**
    1.34       * Return the current context from the object's map.
    1.35       * @return Current context.
    1.36       */
    1.37 -    protected final Context getContext() {
    1.38 -        if (context == null) {
    1.39 -            context = Context.fromClass(getClass());
    1.40 -        }
    1.41 -        return context;
    1.42 -    }
    1.43 -
    1.44 -    /**
    1.45 -     * Set the current context.
    1.46 -     * @param ctx context instance to set
    1.47 -     */
    1.48 -    protected final void setContext(final Context ctx) {
    1.49 -        ctx.getClass();
    1.50 -        this.context = ctx;
    1.51 +    protected Context getContext() {
    1.52 +        return Context.fromClass(getClass());
    1.53      }
    1.54  
    1.55      /**
    1.56 @@ -1482,9 +1450,10 @@
    1.57      /**
    1.58       * Clears the properties from a ScriptObject
    1.59       * (java.util.Map-like method to help ScriptObjectMirror implementation)
    1.60 +     *
    1.61 +     * @param strict strict mode or not
    1.62       */
    1.63 -    public void clear() {
    1.64 -        final boolean strict = isStrictContext();
    1.65 +    public void clear(final boolean strict) {
    1.66          final Iterator<String> iter = propertyIterator();
    1.67          while (iter.hasNext()) {
    1.68              delete(iter.next(), strict);
    1.69 @@ -1568,11 +1537,12 @@
    1.70       *
    1.71       * @param key property key
    1.72       * @param value property value
    1.73 +     * @param strict strict mode or not
    1.74       * @return oldValue if property with same key existed already
    1.75       */
    1.76 -    public Object put(final Object key, final Object value) {
    1.77 +    public Object put(final Object key, final Object value, final boolean strict) {
    1.78          final Object oldValue = get(key);
    1.79 -        set(key, value, isStrictContext());
    1.80 +        set(key, value, strict);
    1.81          return oldValue;
    1.82      }
    1.83  
    1.84 @@ -1582,9 +1552,9 @@
    1.85       * (java.util.Map-like method to help ScriptObjectMirror implementation)
    1.86       *
    1.87       * @param otherMap a {@literal <key,value>} map of properties to add
    1.88 +     * @param strict strict mode or not
    1.89       */
    1.90 -    public void putAll(final Map<?, ?> otherMap) {
    1.91 -        final boolean strict = isStrictContext();
    1.92 +    public void putAll(final Map<?, ?> otherMap, final boolean strict) {
    1.93          for (final Map.Entry<?, ?> entry : otherMap.entrySet()) {
    1.94              set(entry.getKey(), entry.getValue(), strict);
    1.95          }
    1.96 @@ -1595,26 +1565,16 @@
    1.97       * (java.util.Map-like method to help ScriptObjectMirror implementation)
    1.98       *
    1.99       * @param key the key of the property
   1.100 +     * @param strict strict mode or not
   1.101       * @return the oldValue of the removed property
   1.102       */
   1.103 -    public Object remove(final Object key) {
   1.104 +    public Object remove(final Object key, final boolean strict) {
   1.105          final Object oldValue = get(key);
   1.106 -        delete(key, isStrictContext());
   1.107 +        delete(key, strict);
   1.108          return oldValue;
   1.109      }
   1.110  
   1.111      /**
   1.112 -     * Delete a property from the ScriptObject.
   1.113 -     * (to help ScriptObjectMirror implementation)
   1.114 -     *
   1.115 -     * @param key the key of the property
   1.116 -     * @return if the delete was successful or not
   1.117 -     */
   1.118 -    public boolean delete(final Object key) {
   1.119 -        return delete(key, isStrictContext());
   1.120 -    }
   1.121 -
   1.122 -    /**
   1.123       * Return the size of the ScriptObject - i.e. the number of properties
   1.124       * it contains
   1.125       * (java.util.Map-like method to help ScriptObjectMirror implementation)
   1.126 @@ -2333,11 +2293,9 @@
   1.127             return;
   1.128         }
   1.129  
   1.130 -       final boolean isStrict = isStrictContext();
   1.131 -
   1.132         if (newLength > arrayLength) {
   1.133             setArray(getArray().ensure(newLength - 1));
   1.134 -            if (getArray().canDelete(arrayLength, (newLength - 1), isStrict)) {
   1.135 +            if (getArray().canDelete(arrayLength, (newLength - 1), false)) {
   1.136                 setArray(getArray().delete(arrayLength, (newLength - 1)));
   1.137             }
   1.138             return;

mercurial