jdk.nashorn.internal.runtime.ECMAErrors Java Examples

The following examples show how to use jdk.nashorn.internal.runtime.ECMAErrors. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NashornException.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            } else {
                methodName = stripMethodName(methodName);
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #2
Source File: NashornException.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            } else {
                methodName = stripMethodName(methodName);
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #3
Source File: NashornException.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            } else {
                methodName = stripMethodName(methodName);
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #4
Source File: NashornException.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            } else {
                methodName = stripMethodName(methodName);
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[0]);
}
 
Example #5
Source File: NashornException.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
                methodName = "<program>";
            }
            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #6
Source File: NashornException.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            }

            if (methodName.contains(CompilerConstants.ANON_FUNCTION_PREFIX.symbolName())) {
                methodName = "<anonymous>";
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #7
Source File: NashornException.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            }

            if (methodName.contains(CompilerConstants.ANON_FUNCTION_PREFIX.symbolName())) {
                methodName = "<anonymous>";
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #8
Source File: NashornException.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param msg       exception message
 * @param cause     exception cause
 */
protected NashornException(final String msg, final Throwable cause) {
    super(msg, cause == null ? null : cause);
    // This is not so pretty - but it gets the job done. Note that the stack
    // trace has been already filled by "fillInStackTrace" call from
    // Throwable
    // constructor and so we don't pay additional cost for it.

    // Hard luck - no column number info
    this.column = -1;

    // Find the first JavaScript frame by walking and set file, line from it
    // Usually, we should be able to find it in just few frames depth.
    for (final StackTraceElement ste : getStackTrace()) {
        if (ECMAErrors.isScriptFrame(ste)) {
            // Whatever here is compiled from JavaScript code
            this.fileName = ste.getFileName();
            this.line = ste.getLineNumber();
            return;
        }
    }

    this.fileName = null;
    this.line = 0;
}
 
Example #9
Source File: NashornException.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param msg       exception message
 * @param cause     exception cause
 */
protected NashornException(final String msg, final Throwable cause) {
    super(msg, cause == null ? null : cause);
    // This is not so pretty - but it gets the job done. Note that the stack
    // trace has been already filled by "fillInStackTrace" call from
    // Throwable
    // constructor and so we don't pay additional cost for it.

    // Hard luck - no column number info
    this.column = -1;

    // Find the first JavaScript frame by walking and set file, line from it
    // Usually, we should be able to find it in just few frames depth.
    for (final StackTraceElement ste : getStackTrace()) {
        if (ECMAErrors.isScriptFrame(ste)) {
            // Whatever here is compiled from JavaScript code
            this.fileName = ste.getFileName();
            this.line = ste.getLineNumber();
            return;
        }
    }

    this.fileName = null;
    this.line = 0;
}
 
Example #10
Source File: NashornException.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
                methodName = "<program>";
            }
            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #11
Source File: NashornException.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param msg       exception message
 * @param cause     exception cause
 */
protected NashornException(final String msg, final Throwable cause) {
    super(msg, cause == null ? null : cause);
    // This is not so pretty - but it gets the job done. Note that the stack
    // trace has been already filled by "fillInStackTrace" call from
    // Throwable
    // constructor and so we don't pay additional cost for it.

    // Hard luck - no column number info
    this.column = -1;

    // Find the first JavaScript frame by walking and set file, line from it
    // Usually, we should be able to find it in just few frames depth.
    for (final StackTraceElement ste : getStackTrace()) {
        if (ECMAErrors.isScriptFrame(ste)) {
            // Whatever here is compiled from JavaScript code
            this.fileName = ste.getFileName();
            this.line = ste.getLineNumber();
            return;
        }
    }

    this.fileName = null;
    this.line = 0;
}
 
Example #12
Source File: NashornException.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
                methodName = "<program>";
            }
            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #13
Source File: NashornException.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            } else {
                methodName = stripMethodName(methodName);
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #14
Source File: NashornException.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param msg       exception message
 * @param cause     exception cause
 */
protected NashornException(final String msg, final Throwable cause) {
    super(msg, cause == null ? null : cause);
    // This is not so pretty - but it gets the job done. Note that the stack
    // trace has been already filled by "fillInStackTrace" call from
    // Throwable
    // constructor and so we don't pay additional cost for it.

    // Hard luck - no column number info
    this.column = -1;

    // Find the first JavaScript frame by walking and set file, line from it
    // Usually, we should be able to find it in just few frames depth.
    for (final StackTraceElement ste : getStackTrace()) {
        if (ECMAErrors.isScriptFrame(ste)) {
            // Whatever here is compiled from JavaScript code
            this.fileName = ste.getFileName();
            this.line = ste.getLineNumber();
            return;
        }
    }

    this.fileName = null;
    this.line = 0;
}
 
Example #15
Source File: NashornException.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void ensureLineAndFileName() {
    if (lineAndFileNameUnknown) {
        for (final StackTraceElement ste : getStackTrace()) {
            if (ECMAErrors.isScriptFrame(ste)) {
                // Whatever here is compiled from JavaScript code
                fileName = ste.getFileName();
                line = ste.getLineNumber();
                return;
            }
        }

        lineAndFileNameUnknown = false;
    }
}
 
Example #16
Source File: NashornStaticClassLinker.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final LinkRequest request = linkRequest.withoutRuntimeContext(); // Nashorn has no runtime context
    final Object self = request.getReceiver();
    if (self.getClass() != StaticClass.class) {
        return null;
    }
    final Class<?> receiverClass = ((StaticClass) self).getRepresentedClass();

    Bootstrap.checkReflectionAccess(receiverClass, true);
    final CallSiteDescriptor desc = request.getCallSiteDescriptor();
    // We intercept "new" on StaticClass instances to provide additional capabilities
    if ("new".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
        if (! Modifier.isPublic(receiverClass.getModifiers())) {
            throw ECMAErrors.typeError("new.on.nonpublic.javatype", receiverClass.getName());
        }

        // make sure new is on accessible Class
        Context.checkPackageAccess(receiverClass);

        // Is the class abstract? (This includes interfaces.)
        if (NashornLinker.isAbstractClass(receiverClass)) {
            // Change this link request into a link request on the adapter class.
            final Object[] args = request.getArguments();
            args[0] = JavaAdapterFactory.getAdapterClassFor(new Class<?>[] { receiverClass }, null,
                    linkRequest.getCallSiteDescriptor().getLookup());
            final LinkRequest adapterRequest = request.replaceArguments(request.getCallSiteDescriptor(), args);
            final GuardedInvocation gi = checkNullConstructor(delegate(linkerServices, adapterRequest), receiverClass);
            // Finally, modify the guard to test for the original abstract class.
            return gi.replaceMethods(gi.getInvocation(), Guards.getIdentityGuard(self));
        }
        // If the class was not abstract, just delegate linking to the standard StaticClass linker. Make an
        // additional check to ensure we have a constructor. We could just fall through to the next "return"
        // statement, except we also insert a call to checkNullConstructor() which throws an ECMAScript TypeError
        // with a more intuitive message when no suitable constructor is found.
        return checkNullConstructor(delegate(linkerServices, request), receiverClass);
    }
    // In case this was not a "new" operation, just delegate to the the standard StaticClass linker.
    return delegate(linkerServices, request);
}
 
Example #17
Source File: NashornStaticClassLinker.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final LinkRequest request = linkRequest.withoutRuntimeContext(); // Nashorn has no runtime context
    final Object self = request.getReceiver();
    if (self.getClass() != StaticClass.class) {
        return null;
    }
    final Class<?> receiverClass = ((StaticClass) self).getRepresentedClass();

    Bootstrap.checkReflectionAccess(receiverClass, true);
    final CallSiteDescriptor desc = request.getCallSiteDescriptor();
    // We intercept "new" on StaticClass instances to provide additional capabilities
    if ("new".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
        if (! Modifier.isPublic(receiverClass.getModifiers())) {
            throw ECMAErrors.typeError("new.on.nonpublic.javatype", receiverClass.getName());
        }

        // make sure new is on accessible Class
        Context.checkPackageAccess(receiverClass);

        // Is the class abstract? (This includes interfaces.)
        if (NashornLinker.isAbstractClass(receiverClass)) {
            // Change this link request into a link request on the adapter class.
            final Object[] args = request.getArguments();
            args[0] = JavaAdapterFactory.getAdapterClassFor(new Class<?>[] { receiverClass }, null,
                    linkRequest.getCallSiteDescriptor().getLookup());
            final LinkRequest adapterRequest = request.replaceArguments(request.getCallSiteDescriptor(), args);
            final GuardedInvocation gi = checkNullConstructor(delegate(linkerServices, adapterRequest), receiverClass);
            // Finally, modify the guard to test for the original abstract class.
            return gi.replaceMethods(gi.getInvocation(), Guards.getIdentityGuard(self));
        }
        // If the class was not abstract, just delegate linking to the standard StaticClass linker. Make an
        // additional check to ensure we have a constructor. We could just fall through to the next "return"
        // statement, except we also insert a call to checkNullConstructor() which throws an ECMAScript TypeError
        // with a more intuitive message when no suitable constructor is found.
        return checkNullConstructor(delegate(linkerServices, request), receiverClass);
    }
    // In case this was not a "new" operation, just delegate to the the standard StaticClass linker.
    return delegate(linkerServices, request);
}
 
Example #18
Source File: NashornStaticClassLinker.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final LinkRequest request = linkRequest.withoutRuntimeContext(); // Nashorn has no runtime context
    final Object self = request.getReceiver();
    if (self.getClass() != StaticClass.class) {
        return null;
    }
    final Class<?> receiverClass = ((StaticClass) self).getRepresentedClass();

    Bootstrap.checkReflectionAccess(receiverClass, true);
    final CallSiteDescriptor desc = request.getCallSiteDescriptor();
    // We intercept "new" on StaticClass instances to provide additional capabilities
    if ("new".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
        if (! Modifier.isPublic(receiverClass.getModifiers())) {
            throw ECMAErrors.typeError("new.on.nonpublic.javatype", receiverClass.getName());
        }

        // make sure new is on accessible Class
        Context.checkPackageAccess(receiverClass);

        // Is the class abstract? (This includes interfaces.)
        if (NashornLinker.isAbstractClass(receiverClass)) {
            // Change this link request into a link request on the adapter class.
            final Object[] args = request.getArguments();
            args[0] = JavaAdapterFactory.getAdapterClassFor(new Class<?>[] { receiverClass }, null,
                    linkRequest.getCallSiteDescriptor().getLookup());
            final LinkRequest adapterRequest = request.replaceArguments(request.getCallSiteDescriptor(), args);
            final GuardedInvocation gi = checkNullConstructor(delegate(linkerServices, adapterRequest), receiverClass);
            // Finally, modify the guard to test for the original abstract class.
            return gi.replaceMethods(gi.getInvocation(), Guards.getIdentityGuard(self));
        }
        // If the class was not abstract, just delegate linking to the standard StaticClass linker. Make an
        // additional check to ensure we have a constructor. We could just fall through to the next "return"
        // statement, except we also insert a call to checkNullConstructor() which throws an ECMAScript TypeError
        // with a more intuitive message when no suitable constructor is found.
        return checkNullConstructor(delegate(linkerServices, request), receiverClass);
    }
    // In case this was not a "new" operation, just delegate to the the standard StaticClass linker.
    return delegate(linkerServices, request);
}
 
Example #19
Source File: AssignSymbols.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void throwUnprotectedSwitchError(final VarNode varNode) {
    // Block scoped declarations in switch statements without explicit blocks should be declared
    // in a common block that contains all the case clauses. We cannot support this without a
    // fundamental rewrite of how switch statements are handled (case nodes contain blocks and are
    // directly contained by switch node). As a temporary solution we throw a reference error here.
    final String msg = ECMAErrors.getMessage("syntax.error.unprotected.switch.declaration", varNode.isLet() ? "let" : "const");
    throwParserException(msg, varNode);
}
 
Example #20
Source File: NashornException.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void ensureLineAndFileName() {
    if (lineAndFileNameUnknown) {
        for (final StackTraceElement ste : getStackTrace()) {
            if (ECMAErrors.isScriptFrame(ste)) {
                // Whatever here is compiled from JavaScript code
                fileName = ste.getFileName();
                line = ste.getLineNumber();
                return;
            }
        }

        lineAndFileNameUnknown = false;
    }
}
 
Example #21
Source File: AssignSymbols.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void throwUnprotectedSwitchError(final VarNode varNode) {
    // Block scoped declarations in switch statements without explicit blocks should be declared
    // in a common block that contains all the case clauses. We cannot support this without a
    // fundamental rewrite of how switch statements are handled (case nodes contain blocks and are
    // directly contained by switch node). As a temporary solution we throw a reference error here.
    final String msg = ECMAErrors.getMessage("syntax.error.unprotected.switch.declaration", varNode.isLet() ? "let" : "const");
    throwParserException(msg, varNode);
}
 
Example #22
Source File: NashornException.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void ensureLineAndFileName() {
    if (lineAndFileNameUnknown) {
        for (final StackTraceElement ste : getStackTrace()) {
            if (ECMAErrors.isScriptFrame(ste)) {
                // Whatever here is compiled from JavaScript code
                fileName = ste.getFileName();
                line = ste.getLineNumber();
                return;
            }
        }

        lineAndFileNameUnknown = false;
    }
}
 
Example #23
Source File: NashornStaticClassLinker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final LinkRequest request = linkRequest.withoutRuntimeContext(); // Nashorn has no runtime context
    final Object self = request.getReceiver();
    if (self.getClass() != StaticClass.class) {
        return null;
    }
    final Class<?> receiverClass = ((StaticClass) self).getRepresentedClass();

    Bootstrap.checkReflectionAccess(receiverClass, true);
    final CallSiteDescriptor desc = request.getCallSiteDescriptor();
    // We intercept "new" on StaticClass instances to provide additional capabilities
    if ("new".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
        if (! Modifier.isPublic(receiverClass.getModifiers())) {
            throw ECMAErrors.typeError("new.on.nonpublic.javatype", receiverClass.getName());
        }

        // make sure new is on accessible Class
        Context.checkPackageAccess(receiverClass);

        // Is the class abstract? (This includes interfaces.)
        if (NashornLinker.isAbstractClass(receiverClass)) {
            // Change this link request into a link request on the adapter class.
            final Object[] args = request.getArguments();
            args[0] = JavaAdapterFactory.getAdapterClassFor(new Class<?>[] { receiverClass }, null,
                    linkRequest.getCallSiteDescriptor().getLookup());
            final LinkRequest adapterRequest = request.replaceArguments(request.getCallSiteDescriptor(), args);
            final GuardedInvocation gi = checkNullConstructor(delegate(linkerServices, adapterRequest), receiverClass);
            // Finally, modify the guard to test for the original abstract class.
            return gi.replaceMethods(gi.getInvocation(), Guards.getIdentityGuard(self));
        }
        // If the class was not abstract, just delegate linking to the standard StaticClass linker. Make an
        // additional check to ensure we have a constructor. We could just fall through to the next "return"
        // statement, except we also insert a call to checkNullConstructor() which throws an ECMAScript TypeError
        // with a more intuitive message when no suitable constructor is found.
        return checkNullConstructor(delegate(linkerServices, request), receiverClass);
    }
    // In case this was not a "new" operation, just delegate to the the standard StaticClass linker.
    return delegate(linkerServices, request);
}
 
Example #24
Source File: AssignSymbols.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void throwUnprotectedSwitchError(final VarNode varNode) {
    // Block scoped declarations in switch statements without explicit blocks should be declared
    // in a common block that contains all the case clauses. We cannot support this without a
    // fundamental rewrite of how switch statements are handled (case nodes contain blocks and are
    // directly contained by switch node). As a temporary solution we throw a reference error here.
    final String msg = ECMAErrors.getMessage("syntax.error.unprotected.switch.declaration", varNode.isLet() ? "let" : "const");
    throwParserException(msg, varNode);
}
 
Example #25
Source File: NashornException.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void ensureLineAndFileName() {
    if (lineAndFileNameUnknown) {
        for (final StackTraceElement ste : getStackTrace()) {
            if (ECMAErrors.isScriptFrame(ste)) {
                // Whatever here is compiled from JavaScript code
                fileName = ste.getFileName();
                line = ste.getLineNumber();
                return;
            }
        }

        lineAndFileNameUnknown = false;
    }
}
 
Example #26
Source File: Lower.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void throwNotImplementedYet(final String msgId, final Node node) {
    final long token = node.getToken();
    final int line = source.getLine(node.getStart());
    final int column = source.getColumn(node.getStart());
    final String message = ECMAErrors.getMessage("unimplemented." + msgId);
    final String formatted = ErrorManager.format(message, source, line, column, token);
    throw new RuntimeException(formatted);
}
 
Example #27
Source File: NashornException.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void ensureLineAndFileName() {
    if (lineAndFileNameUnknown) {
        for (final StackTraceElement ste : getStackTrace()) {
            if (ECMAErrors.isScriptFrame(ste)) {
                // Whatever here is compiled from JavaScript code
                fileName = ste.getFileName();
                line = ste.getLineNumber();
                return;
            }
        }

        lineAndFileNameUnknown = false;
    }
}
 
Example #28
Source File: AssignSymbols.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private void throwUnprotectedSwitchError(final VarNode varNode) {
    // Block scoped declarations in switch statements without explicit blocks should be declared
    // in a common block that contains all the case clauses. We cannot support this without a
    // fundamental rewrite of how switch statements are handled (case nodes contain blocks and are
    // directly contained by switch node). As a temporary solution we throw a reference error here.
    final String msg = ECMAErrors.getMessage("syntax.error.unprotected.switch.declaration", varNode.isLet() ? "let" : "const");
    throwParserException(msg, varNode);
}
 
Example #29
Source File: AssignSymbols.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void throwUnprotectedSwitchError(final VarNode varNode) {
    // Block scoped declarations in switch statements without explicit blocks should be declared
    // in a common block that contains all the case clauses. We cannot support this without a
    // fundamental rewrite of how switch statements are handled (case nodes contain blocks and are
    // directly contained by switch node). As a temporary solution we throw a reference error here.
    final String msg = ECMAErrors.getMessage("syntax.error.unprotected.switch.declaration", varNode.isLet() ? "let" : "const");
    throwParserException(msg, varNode);
}
 
Example #30
Source File: NashornException.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private void ensureLineAndFileName() {
    if (lineAndFileNameUnknown) {
        for (final StackTraceElement ste : getStackTrace()) {
            if (ECMAErrors.isScriptFrame(ste)) {
                // Whatever here is compiled from JavaScript code
                fileName = ste.getFileName();
                line = ste.getLineNumber();
                return;
            }
        }

        lineAndFileNameUnknown = false;
    }
}