• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ECMAErrors类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中jdk.nashorn.internal.runtime.ECMAErrors的典型用法代码示例。如果您正苦于以下问题:Java ECMAErrors类的具体用法?Java ECMAErrors怎么用?Java ECMAErrors使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ECMAErrors类属于jdk.nashorn.internal.runtime包,在下文中一共展示了ECMAErrors类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: NashornException

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:NashornException.java


示例2: getScriptFrames

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
/**
 * 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()]);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:NashornException.java


示例3: getScriptFrames

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
/**
 * 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]);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:NashornException.java


示例4: getScriptFrames

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
/**
 * 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()]);
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:26,代码来源:NashornException.java


示例5: getScriptFrames

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
/**
 * 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()]);
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:23,代码来源:NashornException.java


示例6: getGuardedInvocation

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
@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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:NashornStaticClassLinker.java


示例7: checkConstAssignment

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
private void checkConstAssignment(final IdentNode ident) {
    // Check for reassignment of constant
    final Symbol symbol = ident.getSymbol();
    if (symbol.isConst()) {
        throwParserException(ECMAErrors.getMessage("syntax.error.assign.constant", symbol.getName()), ident);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:AssignSymbols.java


示例8: throwUnprotectedSwitchError

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:AssignSymbols.java


示例9: ensureLineAndFileName

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:NashornException.java


示例10: throwNotImplementedYet

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:Lower.java


示例11: typeError

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
ECMAException typeError() {
    return ECMAErrors.typeError("extend." + outcome, classList);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:AdaptationResult.java


示例12: checkNullConstructor

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
private static GuardedInvocation checkNullConstructor(final GuardedInvocation ctorInvocation, final Class<?> receiverClass) {
    if(ctorInvocation == null) {
        throw ECMAErrors.typeError("no.constructor.matches.args", receiverClass.getName());
    }
    return ctorInvocation;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:NashornStaticClassLinker.java


示例13: syntaxError

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
private ParserException syntaxError(final int start, final String reason) {
    final String message = ECMAErrors.getMessage("syntax.error.invalid.json", reason);
    return error(message, start);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:JSONParser.java


示例14: typeError

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
ECMAException typeError() {
    return ECMAErrors.typeError(cause, "extend." + outcome, messageArgs);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:AdaptationResult.java


示例15: getGuardedInvocation

import jdk.nashorn.internal.runtime.ECMAErrors; //导入依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception {
    final Object self = request.getReceiver();
    if (self == null || 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 (NamedOperation.getBaseOperation(desc.getOperation()) == StandardOperation.NEW) {
        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();
            final MethodHandles.Lookup lookup =
                    NashornCallSiteDescriptor.getLookupInternal(request.getCallSiteDescriptor());

            args[0] = JavaAdapterFactory.getAdapterClassFor(new Class<?>[] { receiverClass }, null, lookup);
            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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:NashornStaticClassLinker.java



注:本文中的jdk.nashorn.internal.runtime.ECMAErrors类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Processor类代码示例发布时间:2022-05-22
下一篇:
Java MultiCollector类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap