8008291: Add more tests for better coverage of objects, scripting and parser packages

Fri, 15 Feb 2013 18:30:19 +0530

author
sundar
date
Fri, 15 Feb 2013 18:30:19 +0530
changeset 97
757a49aaad02
parent 96
e478708faa22
child 98
5851c5dac260

8008291: Add more tests for better coverage of objects, scripting and parser packages
Reviewed-by: lagergren, jlaskey

src/jdk/nashorn/internal/parser/AbstractParser.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/parser/Scanner.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/BitVector.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/Context.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/QuotedStringTokenizer.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/RegExpScanner.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/Source.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/tools/Shell.java file | annotate | diff | comparison | revisions
test/script/basic/NASHORN-401.js file | annotate | diff | comparison | revisions
test/script/basic/NASHORN-401.js.EXPECTED file | annotate | diff | comparison | revisions
test/script/basic/assign_builtin_func_props.js file | annotate | diff | comparison | revisions
test/script/basic/debugger.js file | annotate | diff | comparison | revisions
test/script/basic/yield.js file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/scripting/MultipleEngineTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/scripting/Window.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/parser/ParserTest.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/parser/AbstractParser.java	Fri Feb 15 09:44:15 2013 +0100
     1.2 +++ b/src/jdk/nashorn/internal/parser/AbstractParser.java	Fri Feb 15 18:30:19 2013 +0530
     1.3 @@ -101,15 +101,6 @@
     1.4      }
     1.5  
     1.6      /**
     1.7 -     * Get the Source
     1.8 -     *
     1.9 -     * @return the Source
    1.10 -     */
    1.11 -    public Source getSource() {
    1.12 -        return source;
    1.13 -    }
    1.14 -
    1.15 -    /**
    1.16       * Get the ith token.
    1.17       *
    1.18       * @param i Index of token.
    1.19 @@ -261,7 +252,7 @@
    1.20       * @return the message string
    1.21       */
    1.22      protected final String expectMessage(final TokenType expected) {
    1.23 -        final String tokenString = Token.toString(source, token, false);
    1.24 +        final String tokenString = Token.toString(source, token);
    1.25          String msg;
    1.26  
    1.27          if (expected == null) {
     2.1 --- a/src/jdk/nashorn/internal/parser/Scanner.java	Fri Feb 15 09:44:15 2013 +0100
     2.2 +++ b/src/jdk/nashorn/internal/parser/Scanner.java	Fri Feb 15 18:30:19 2013 +0530
     2.3 @@ -59,7 +59,7 @@
     2.4       * @param start   position index in content where to start
     2.5       * @param length  length of input
     2.6       */
     2.7 -    public Scanner(final char[] content, final int line, final int start, final int length) {
     2.8 +    protected Scanner(final char[] content, final int line, final int start, final int length) {
     2.9          this.content  = content;
    2.10          this.position = start;
    2.11          this.limit    = start + length;
    2.12 @@ -75,7 +75,7 @@
    2.13       *
    2.14       * @param content content to scan
    2.15       */
    2.16 -    public Scanner(final String content) {
    2.17 +    protected Scanner(final String content) {
    2.18          this(content.toCharArray(), 0, 0, content.length());
    2.19      }
    2.20  
     3.1 --- a/src/jdk/nashorn/internal/runtime/BitVector.java	Fri Feb 15 09:44:15 2013 +0100
     3.2 +++ b/src/jdk/nashorn/internal/runtime/BitVector.java	Fri Feb 15 18:30:19 2013 +0530
     3.3 @@ -67,7 +67,7 @@
     3.4       * @param bits a bits array from another bit vector
     3.5       */
     3.6      public BitVector(final long[] bits) {
     3.7 -        this.bits = bits;
     3.8 +        this.bits = bits.clone();
     3.9      }
    3.10  
    3.11      /**
    3.12 @@ -75,7 +75,7 @@
    3.13       * @param other the source
    3.14       */
    3.15      public void copy(final BitVector other) {
    3.16 -        bits = Arrays.copyOf(other.bits, other.bits.length);
    3.17 +        bits = other.bits.clone();
    3.18      }
    3.19  
    3.20      /**
     4.1 --- a/src/jdk/nashorn/internal/runtime/Context.java	Fri Feb 15 09:44:15 2013 +0100
     4.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java	Fri Feb 15 18:30:19 2013 +0530
     4.3 @@ -672,7 +672,7 @@
     4.4              return evaluateSource(source, scope, scope);
     4.5          }
     4.6  
     4.7 -        typeError("cant.load.script", ScriptRuntime.safeToString(source));
     4.8 +        typeError("cant.load.script", ScriptRuntime.safeToString(from));
     4.9  
    4.10          return UNDEFINED;
    4.11      }
     5.1 --- a/src/jdk/nashorn/internal/runtime/QuotedStringTokenizer.java	Fri Feb 15 09:44:15 2013 +0100
     5.2 +++ b/src/jdk/nashorn/internal/runtime/QuotedStringTokenizer.java	Fri Feb 15 18:30:19 2013 +0530
     5.3 @@ -34,7 +34,7 @@
     5.4   * the separators are quoted either by ' and ", or whatever quotes the user
     5.5   * supplies they will be ignored and considered part of another token
     5.6   */
     5.7 -public class QuotedStringTokenizer {
     5.8 +public final class QuotedStringTokenizer {
     5.9      private final LinkedList<String> tokens;
    5.10  
    5.11      private final char quotes[];
    5.12 @@ -72,7 +72,7 @@
    5.13       *            all the characters that should be accepted as quotes, default
    5.14       *            is ' or "
    5.15       */
    5.16 -    public QuotedStringTokenizer(final String str, final String delim, final char[] quotes) {
    5.17 +    private QuotedStringTokenizer(final String str, final String delim, final char[] quotes) {
    5.18          this.quotes = quotes;
    5.19  
    5.20          boolean delimIsWhitespace = true;
     6.1 --- a/src/jdk/nashorn/internal/runtime/RegExpScanner.java	Fri Feb 15 09:44:15 2013 +0100
     6.2 +++ b/src/jdk/nashorn/internal/runtime/RegExpScanner.java	Fri Feb 15 18:30:19 2013 +0530
     6.3 @@ -614,11 +614,7 @@
     6.4          final Token token = new Token(Token.Type.PATTERN);
     6.5  
     6.6          final Token child = disjunction();
     6.7 -        if (child != null) {
     6.8 -            return token.add(child);
     6.9 -        }
    6.10 -
    6.11 -        return null;
    6.12 +        return token.add(child);
    6.13      }
    6.14  
    6.15      /*
     7.1 --- a/src/jdk/nashorn/internal/runtime/Source.java	Fri Feb 15 09:44:15 2013 +0100
     7.2 +++ b/src/jdk/nashorn/internal/runtime/Source.java	Fri Feb 15 18:30:19 2013 +0530
     7.3 @@ -201,18 +201,6 @@
     7.4      }
     7.5  
     7.6      /**
     7.7 -     * Fetch a portion of source content associated with a range of tokens.
     7.8 -     * @param startTokenDesc Starting token descriptor.
     7.9 -     * @param endTokenDesc   Ending token descriptor.
    7.10 -     * @return Source content portion.
    7.11 -     */
    7.12 -    public String getString(final long startTokenDesc, final long endTokenDesc) {
    7.13 -        final int start = Token.descPosition(startTokenDesc);
    7.14 -        final int end   = Token.descPosition(endTokenDesc) + Token.descLength(endTokenDesc);
    7.15 -        return new String(content, start, end - start);
    7.16 -    }
    7.17 -
    7.18 -    /**
    7.19       * Returns the source URL of this script Source. Can be null if Source
    7.20       * was created from a String or a char[].
    7.21       *
     8.1 --- a/src/jdk/nashorn/tools/Shell.java	Fri Feb 15 09:44:15 2013 +0100
     8.2 +++ b/src/jdk/nashorn/tools/Shell.java	Fri Feb 15 18:30:19 2013 +0530
     8.3 @@ -192,12 +192,14 @@
     8.4          final Options options = new Options("nashorn", werr);
     8.5  
     8.6          // parse options
     8.7 -        try {
     8.8 -            options.process(args);
     8.9 -        } catch (final IllegalArgumentException e) {
    8.10 -            werr.println(bundle.getString("shell.usage"));
    8.11 -            options.displayHelp(e);
    8.12 -            return null;
    8.13 +        if (args != null) {
    8.14 +            try {
    8.15 +                options.process(args);
    8.16 +            } catch (final IllegalArgumentException e) {
    8.17 +                werr.println(bundle.getString("shell.usage"));
    8.18 +                options.displayHelp(e);
    8.19 +                return null;
    8.20 +            }
    8.21          }
    8.22  
    8.23          // detect scripting mode by any source's first character being '#'
     9.1 --- a/test/script/basic/NASHORN-401.js	Fri Feb 15 09:44:15 2013 +0100
     9.2 +++ b/test/script/basic/NASHORN-401.js	Fri Feb 15 18:30:19 2013 +0530
     9.3 @@ -34,6 +34,7 @@
     9.4  print(t.method2(10.2));
     9.5  print(t.method2("a"));
     9.6  
     9.7 +print(t.method3(10));
     9.8  print(t.method3("10"));
     9.9  print(t.method3("10.2"));
    9.10  print(t.method3("foo"));
    10.1 --- a/test/script/basic/NASHORN-401.js.EXPECTED	Fri Feb 15 09:44:15 2013 +0100
    10.2 +++ b/test/script/basic/NASHORN-401.js.EXPECTED	Fri Feb 15 18:30:19 2013 +0530
    10.3 @@ -1,6 +1,7 @@
    10.4  int method 2
    10.5  double method 2
    10.6  string method 2
    10.7 +int method 3: 10
    10.8  double method 3: 10.0
    10.9  double method 3: 10.2
   10.10  double method 3: NaN
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/script/basic/assign_builtin_func_props.js	Fri Feb 15 18:30:19 2013 +0530
    11.3 @@ -0,0 +1,56 @@
    11.4 +/*
    11.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.7 + *
    11.8 + * This code is free software; you can redistribute it and/or modify it
    11.9 + * under the terms of the GNU General Public License version 2 only, as
   11.10 + * published by the Free Software Foundation.
   11.11 + *
   11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   11.15 + * version 2 for more details (a copy is included in the LICENSE file that
   11.16 + * accompanied this code).
   11.17 + *
   11.18 + * You should have received a copy of the GNU General Public License version
   11.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   11.21 + *
   11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   11.23 + * or visit www.oracle.com if you need additional information or have any
   11.24 + * questions.
   11.25 + */
   11.26 +
   11.27 +
   11.28 +/**
   11.29 + * Check that we can assign to all properties from builtin functions and their
   11.30 + * prototypes. This is to make sure all such properties are writable.
   11.31 + *
   11.32 + * @test
   11.33 + * @run
   11.34 + */
   11.35 +
   11.36 +(function() {
   11.37 +    var PropNamesGetter = Object.getOwnPropertyNames;
   11.38 +    var ObjectType = Object;
   11.39 +
   11.40 +    function assignAll(obj) {
   11.41 +        if (! (obj instanceof ObjectType)) {
   11.42 +            return;
   11.43 +        }
   11.44 +        var props = PropNamesGetter(obj);
   11.45 +        for (var p in props) {
   11.46 +            var value = obj[props[p]];
   11.47 +            obj[props[p]] = value;
   11.48 +        }
   11.49 +    }
   11.50 +
   11.51 +    var globalProps = PropNamesGetter(this);
   11.52 +    for (var i in globalProps) {
   11.53 +        var prop = globalProps[i];
   11.54 +        if (typeof this[prop] == 'function') {
   11.55 +            assignAll(this[prop].prototype);
   11.56 +            assignAll(this[prop]);
   11.57 +        }
   11.58 +    }
   11.59 +})();
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/test/script/basic/debugger.js	Fri Feb 15 18:30:19 2013 +0530
    12.3 @@ -0,0 +1,32 @@
    12.4 +/*
    12.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    12.7 + *
    12.8 + * This code is free software; you can redistribute it and/or modify it
    12.9 + * under the terms of the GNU General Public License version 2 only, as
   12.10 + * published by the Free Software Foundation.
   12.11 + *
   12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   12.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   12.15 + * version 2 for more details (a copy is included in the LICENSE file that
   12.16 + * accompanied this code).
   12.17 + *
   12.18 + * You should have received a copy of the GNU General Public License version
   12.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   12.21 + *
   12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   12.23 + * or visit www.oracle.com if you need additional information or have any
   12.24 + * questions.
   12.25 + */
   12.26 +
   12.27 +
   12.28 +/**
   12.29 + * Check that the debugger statement is parsed and does nothing as of now.
   12.30 + *
   12.31 + * @test
   12.32 + * @run
   12.33 + */
   12.34 +
   12.35 +debugger;
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/test/script/basic/yield.js	Fri Feb 15 18:30:19 2013 +0530
    13.3 @@ -0,0 +1,34 @@
    13.4 +/*
    13.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    13.7 + *
    13.8 + * This code is free software; you can redistribute it and/or modify it
    13.9 + * under the terms of the GNU General Public License version 2 only, as
   13.10 + * published by the Free Software Foundation.
   13.11 + *
   13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   13.15 + * version 2 for more details (a copy is included in the LICENSE file that
   13.16 + * accompanied this code).
   13.17 + *
   13.18 + * You should have received a copy of the GNU General Public License version
   13.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   13.21 + *
   13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   13.23 + * or visit www.oracle.com if you need additional information or have any
   13.24 + * questions.
   13.25 + */
   13.26 +
   13.27 +
   13.28 +/**
   13.29 + * Check yield keyword is parsed and yield statement does nothing (yet).
   13.30 + *
   13.31 + * @test
   13.32 + * @run
   13.33 + */
   13.34 +
   13.35 +function func() {
   13.36 +    yield 2;
   13.37 +}
    14.1 --- a/test/src/jdk/nashorn/api/scripting/MultipleEngineTest.java	Fri Feb 15 09:44:15 2013 +0100
    14.2 +++ b/test/src/jdk/nashorn/api/scripting/MultipleEngineTest.java	Fri Feb 15 18:30:19 2013 +0530
    14.3 @@ -28,7 +28,6 @@
    14.4  import javax.script.ScriptEngine;
    14.5  import javax.script.ScriptEngineManager;
    14.6  import javax.script.ScriptException;
    14.7 -import org.testng.TestNG;
    14.8  import org.testng.annotations.Test;
    14.9  
   14.10  /**
   14.11 @@ -37,10 +36,6 @@
   14.12   */
   14.13  
   14.14  public class MultipleEngineTest {
   14.15 -    public static void main(final String[] args) {
   14.16 -        TestNG.main(args);
   14.17 -    }
   14.18 -
   14.19      @Test
   14.20      public void createAndUseManyEngine() throws ScriptException {
   14.21          final ScriptEngineManager m = new ScriptEngineManager();
    15.1 --- a/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Fri Feb 15 09:44:15 2013 +0100
    15.2 +++ b/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Fri Feb 15 18:30:19 2013 +0530
    15.3 @@ -50,7 +50,6 @@
    15.4  import jdk.nashorn.internal.runtime.Version;
    15.5  import netscape.javascript.JSObject;
    15.6  import org.testng.Assert;
    15.7 -import org.testng.TestNG;
    15.8  import org.testng.annotations.Test;
    15.9  
   15.10  /**
   15.11 @@ -58,10 +57,6 @@
   15.12   */
   15.13  public class ScriptEngineTest {
   15.14  
   15.15 -    public static void main(final String[] args) {
   15.16 -        TestNG.main(args);
   15.17 -    }
   15.18 -
   15.19      private void log(String msg) {
   15.20          org.testng.Reporter.log(msg, true);
   15.21      }
   15.22 @@ -132,6 +127,7 @@
   15.23          assertEquals(fac.getEngineName(), "Oracle Nashorn");
   15.24          assertEquals(fac.getEngineVersion(), Version.version());
   15.25          assertEquals(fac.getOutputStatement("context"), "print(context)");
   15.26 +        assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
   15.27          assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
   15.28  
   15.29          boolean seenJS = false;
   15.30 @@ -808,6 +804,9 @@
   15.31                  fail("obj.prop is not deleted!");
   15.32              }
   15.33  
   15.34 +            // Simple eval tests
   15.35 +            assertEquals(obj.eval("typeof Object"), "function");
   15.36 +            assertEquals(obj.eval("'nashorn'.substring(3)"), "horn");
   15.37          } catch (final Exception exp) {
   15.38              exp.printStackTrace();
   15.39              fail(exp.getMessage());
    16.1 --- a/test/src/jdk/nashorn/api/scripting/Window.java	Fri Feb 15 09:44:15 2013 +0100
    16.2 +++ b/test/src/jdk/nashorn/api/scripting/Window.java	Fri Feb 15 18:30:19 2013 +0530
    16.3 @@ -59,17 +59,8 @@
    16.4          return self.setTimeout(code, delay);
    16.5      }
    16.6  
    16.7 -    public static void clearTimeout(final Window self, final int id) {
    16.8 -        self.clearTimeout(id);
    16.9 -    }
   16.10 -
   16.11      public int setTimeout(final String code, final int delay) {
   16.12          System.out.println("window.setTimeout: " + delay + ", code: " + code);
   16.13          return 0;
   16.14      }
   16.15 -
   16.16 -    public void clearTimeout(final int id) {
   16.17 -        System.out.println("window.clearTimeout: " + id);
   16.18 -    }
   16.19 -
   16.20  }
    17.1 --- a/test/src/jdk/nashorn/internal/parser/ParserTest.java	Fri Feb 15 09:44:15 2013 +0100
    17.2 +++ b/test/src/jdk/nashorn/internal/parser/ParserTest.java	Fri Feb 15 18:30:19 2013 +0530
    17.3 @@ -26,8 +26,6 @@
    17.4  package jdk.nashorn.internal.parser;
    17.5  
    17.6  import java.io.File;
    17.7 -import jdk.nashorn.internal.codegen.Compiler;
    17.8 -import jdk.nashorn.internal.codegen.CompilerConstants;
    17.9  import jdk.nashorn.internal.runtime.Context;
   17.10  import jdk.nashorn.internal.runtime.ErrorManager;
   17.11  import jdk.nashorn.internal.runtime.ScriptObject;

mercurial