~james-page/ubuntu/natty/rhino/fix-304702

« back to all changes in this revision

Viewing changes to testsrc/org/mozilla/javascript/tests/ContextFactoryTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan, Marcus Better, Matthias Klose, Damien Raude-Morvan
  • Date: 2009-04-13 02:40:15 UTC
  • mfrom: (11.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090413024015-i21xnoehukpipbcw
Tags: 1.7R2-1
[ Marcus Better ]
* Updated package descriptions.

[ Matthias Klose ]
* (Build-)depend on default-jre-headless/-jdk.
* Drop alternate dependencies on java2-runtime-headless and
  java2-runtime-headless. The binary package is currently built to
  require a java5 runtime.

[ Damien Raude-Morvan ]
* New upstream release.
  - new 02_exclude-jdk15 patch to exclude already compiled classes
    for jdk15 rebuild: gcj doesn't handle compiling classes already
    on its classpath
  - new "rhino-debugger" launcher for Rhino Debugger Swing UI
  - update "rhino" launcher to exclude OpenJDK bundled rhino (Closes: #512498)
* debian/{postinst,prerm }: scripts should take care of errors,
  add set -e before any instruction
* debian/rules: add new get-orig-source target using uscan
* debian/control:
  - Build-Depends on specialized default-jdk-builddep instead of
  default-jdk
  - Bump Standards-Version to 3.8.1: Wrap Uploaders field
  - add Depends on ${misc:Depends}

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * 
 
3
 */
 
4
package org.mozilla.javascript.tests;
 
5
 
 
6
import junit.framework.TestCase;
 
7
 
 
8
import org.mozilla.javascript.Context;
 
9
import org.mozilla.javascript.ContextFactory;
 
10
import org.mozilla.javascript.Scriptable;
 
11
import org.mozilla.javascript.RhinoException;
 
12
 
 
13
/**
 
14
 * @author Norris Boyd
 
15
 */
 
16
public class ContextFactoryTest extends TestCase {
 
17
    static class MyFactory extends ContextFactory {
 
18
        @Override
 
19
        public boolean hasFeature(Context cx, int featureIndex)
 
20
        {
 
21
            switch (featureIndex) {
 
22
                case Context.FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME:
 
23
                    return true;
 
24
            }
 
25
            return super.hasFeature(cx, featureIndex);
 
26
        }
 
27
    }
 
28
 
 
29
    public void testCustomContextFactory() {
 
30
        ContextFactory factory = new MyFactory();
 
31
        Context cx = factory.enterContext();
 
32
        try {
 
33
            Scriptable globalScope = cx.initStandardObjects();
 
34
            // Test that FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME is enabled
 
35
            Object result = cx.evaluateString(globalScope,
 
36
                    "var obj = {};" +
 
37
                    "function obj.foo() { return 'bar'; }" +
 
38
                    "obj.foo();",
 
39
                    "test source", 1, null);
 
40
            assertEquals("bar", result);
 
41
        } catch (RhinoException e) {
 
42
            fail(e.toString());
 
43
        } finally {
 
44
            Context.exit();
 
45
        }
 
46
    }
 
47
 }