8016453: loadWithNewGlobal does not allow apply operation

Wed, 12 Jun 2013 11:22:06 -0300

author
jlaskey
date
Wed, 12 Jun 2013 11:22:06 -0300
changeset 342
aa16622193e1
parent 341
df5d7f34e35e
child 343
d26e069353c0

8016453: loadWithNewGlobal does not allow apply operation
Reviewed-by: hannesw, sundar
Contributed-by: james.laskey@oracle.com

samples/test.js file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/Global.java file | annotate | diff | comparison | revisions
     1.1 --- a/samples/test.js	Tue Jun 11 17:50:10 2013 +0200
     1.2 +++ b/samples/test.js	Wed Jun 12 11:22:06 2013 -0300
     1.3 @@ -1,21 +1,21 @@
     1.4  /*
     1.5   * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 - * 
     1.7 + *
     1.8   * Redistribution and use in source and binary forms, with or without
     1.9   * modification, are permitted provided that the following conditions
    1.10   * are met:
    1.11 - * 
    1.12 + *
    1.13   *   - Redistributions of source code must retain the above copyright
    1.14   *     notice, this list of conditions and the following disclaimer.
    1.15 - * 
    1.16 + *
    1.17   *   - Redistributions in binary form must reproduce the above copyright
    1.18   *     notice, this list of conditions and the following disclaimer in the
    1.19   *     documentation and/or other materials provided with the distribution.
    1.20 - * 
    1.21 + *
    1.22   *   - Neither the name of Oracle nor the names of its
    1.23   *     contributors may be used to endorse or promote products derived
    1.24   *     from this software without specific prior written permission.
    1.25 - * 
    1.26 + *
    1.27   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
    1.28   * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    1.29   * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    1.30 @@ -30,3 +30,4 @@
    1.31   */
    1.32  
    1.33  print("Hello World");
    1.34 +
     2.1 --- a/src/jdk/nashorn/internal/objects/Global.java	Tue Jun 11 17:50:10 2013 +0200
     2.2 +++ b/src/jdk/nashorn/internal/objects/Global.java	Wed Jun 12 11:22:06 2013 -0300
     2.3 @@ -37,6 +37,7 @@
     2.4  import java.lang.reflect.Field;
     2.5  import java.security.AccessController;
     2.6  import java.security.PrivilegedAction;
     2.7 +import java.util.Arrays;
     2.8  import java.util.LinkedHashMap;
     2.9  import java.util.List;
    2.10  import java.util.Map;
    2.11 @@ -372,7 +373,7 @@
    2.12      private static final MethodHandle PRINT             = findOwnMH("print",             Object.class, Object.class, Object[].class);
    2.13      private static final MethodHandle PRINTLN           = findOwnMH("println",           Object.class, Object.class, Object[].class);
    2.14      private static final MethodHandle LOAD              = findOwnMH("load",              Object.class, Object.class, Object.class);
    2.15 -    private static final MethodHandle LOADWITHNEWGLOBAL = findOwnMH("loadWithNewGlobal", Object.class, Object.class, Object.class, Object[].class);
    2.16 +    private static final MethodHandle LOADWITHNEWGLOBAL = findOwnMH("loadWithNewGlobal", Object.class, Object.class, Object[].class);
    2.17      private static final MethodHandle EXIT              = findOwnMH("exit",              Object.class, Object.class, Object.class);
    2.18  
    2.19      private final Context context;
    2.20 @@ -750,17 +751,21 @@
    2.21      /**
    2.22       * Global loadWithNewGlobal implementation - Nashorn extension
    2.23       *
    2.24 -     * @param self    scope
    2.25 -     * @param source  source to load
    2.26 -     * @param args (optional) arguments to be passed to the loaded script
    2.27 +     * @param self scope
    2.28 +     * @param args from plus (optional) arguments to be passed to the loaded script
    2.29       *
    2.30 -     * @return result of load (undefined)
    2.31 +     * @return result of load (may be undefined)
    2.32       *
    2.33       * @throws IOException if source could not be read
    2.34       */
    2.35 -    public static Object loadWithNewGlobal(final Object self, final Object source, final Object...args) throws IOException {
    2.36 +    public static Object loadWithNewGlobal(final Object self, final Object...args) throws IOException {
    2.37          final Global global = Global.instance();
    2.38 -        return global.context.loadWithNewGlobal(source, args);
    2.39 +        final int length = args.length;
    2.40 +        final boolean hasArgs = 0 < length;
    2.41 +        final Object from = hasArgs ? args[0] : UNDEFINED;
    2.42 +        final Object[] arguments = hasArgs ? Arrays.copyOfRange(args, 1, length) : args;
    2.43 +
    2.44 +        return global.context.loadWithNewGlobal(from, arguments);
    2.45      }
    2.46  
    2.47      /**

mercurial