当前位置: 首页>>代码示例>>Java>>正文


Java AbstractJSObject类代码示例

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


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

示例1: bindToExpression

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
@SuppressWarnings("unused")
private static Object bindToExpression(final Object fn, final Object receiver) {
    if (fn instanceof ScriptFunction) {
        return bindToExpression((ScriptFunction) fn, receiver);
    } else if (fn instanceof ScriptObjectMirror) {
        final ScriptObjectMirror mirror = (ScriptObjectMirror)fn;
        if (mirror.isFunction()) {
            // We need to make sure correct 'this' is used for calls with Ident call
            // expressions. We do so here using an AbstractJSObject instance.
            return new AbstractJSObject() {
                @Override
                public Object call(final Object thiz, final Object... args) {
                    return mirror.call(withFilterExpression(receiver), args);
                }
            };
        }
    }

    return fn;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:WithObject.java

示例2: hidingInternalObjectsForJSObjectTest

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
@Test
public void hidingInternalObjectsForJSObjectTest() throws Exception {
    final ScriptEngineManager engineManager = new ScriptEngineManager();
    final ScriptEngine e = engineManager.getEngineByName("nashorn");

    final String code = "function func(obj) { obj.foo = [5, 5]; obj.bar = {} }";
    e.eval(code);

    // call the exposed function but pass user defined JSObject impl as argument
    ((Invocable)e).invokeFunction("func", new AbstractJSObject() {
        @Override
        public void setMember(final String name, final Object value) {
            // make sure that wrapped objects are passed (and not internal impl. objects)
            assertTrue(value.getClass() == ScriptObjectMirror.class);
        }
    });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:PluggableJSObjectTest.java

示例3: getMember

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
@Override
public Object getMember(final String name) {
   switch (name) {
      case "length":
          return buf.capacity();
      case "buf":
          // return a 'function' value for this property
          return new AbstractJSObject() {
              @Override
              public Object call(final Object thiz, final Object... args) {
                  return BufferArray.this.buf;
              }

              // yes, I'm a function !
              @Override
              public boolean isFunction() {
                  return true;
              }
          };
      default:
          break;
   }
   return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:BufferArray.java

示例4: enqueueElementsChanged

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
protected void enqueueElementsChanged() {
    if (boundToDataElements != null) {
        Scripts.unlisten(boundToDataElements);
        boundToDataElements = null;
    }
    elementsChangedEnqueued = () -> {
        if (elementsChangedEnqueued == this) {
            elementsChangedEnqueued = null;
            if (data != null && Scripts.isInitialized()) {
                boundToDataElements = Scripts.getSpace().listenElements(data, new AbstractJSObject() {

                    @Override
                    public Object call(Object thiz, Object... args) {
                        enqueueElementsDataChanged();
                        return null;
                    }

                });
            }
            fireElementsChanged();
        }
    };
    EventQueue.invokeLater(elementsChangedEnqueued);
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:25,代码来源:ArrayModel.java

示例5: nashornExportedLinkerJSObjectTest

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
@Test
public void nashornExportedLinkerJSObjectTest() {
    final DynamicLinkerFactory factory = newDynamicLinkerFactory(false);
    final DynamicLinker linker = factory.createLinker();

    final MethodType mt = MethodType.methodType(Object.class, Object.class);
    final Operation op = GET_PROPERTY.named("foo");
    final CallSite cs = linker.link(new SimpleRelinkableCallSite(new CallSiteDescriptor(
            MethodHandles.publicLookup(), op, mt)));
    final boolean[] reachedGetMember = new boolean[1];
    // check that the nashorn exported linker can be used for user defined JSObject
    final Object obj = new AbstractJSObject() {
            @Override
            public Object getMember(final String name) {
                reachedGetMember[0] = true;
                return name.equals("foo")? "bar" : "<unknown>";
            }
        };

    Object value = null;
    try {
        value = cs.getTarget().invoke(obj);
    } catch (final Throwable th) {
        throw new RuntimeException(th);
    }

    Assert.assertTrue(reachedGetMember[0]);
    Assert.assertEquals(value, "bar");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:DynamicLinkerFactoryTest.java

示例6: setupTest

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
@BeforeClass
public void setupTest() {
    engine = new ScriptEngineManager().getEngineByName("js");
    engine.put("f", new AbstractJSObject() {
        @Override
        public boolean isFunction() {
            return true;
        }
        @Override
        public Object call(final Object thiz, final Object... args) {
            return Arrays.deepToString(args);
        }
    });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:JDK_8148140_Test.java

示例7: nashornExportedLinkerJSObjectTest

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
@Test
public void nashornExportedLinkerJSObjectTest() {
    final DynamicLinkerFactory factory = newDynamicLinkerFactory(false);
    final DynamicLinker linker = factory.createLinker();

    final MethodType mt = MethodType.methodType(Object.class, Object.class);
    final NamedOperation op = new NamedOperation(StandardOperation.GET_PROPERTY, "foo");
    final CallSite cs = linker.link(new SimpleRelinkableCallSite(new CallSiteDescriptor(
            MethodHandles.publicLookup(), op, mt)));
    final boolean[] reachedGetMember = new boolean[1];
    // check that the nashorn exported linker can be used for user defined JSObject
    Object obj = new AbstractJSObject() {
            @Override
            public Object getMember(String name) {
                reachedGetMember[0] = true;
                return name.equals("foo")? "bar" : "<unknown>";
            }
        };

    Object value = null;
    try {
        value = cs.getTarget().invoke(obj);
    } catch (Throwable th) {
        throw new RuntimeException(th);
    }

    Assert.assertTrue(reachedGetMember[0]);
    Assert.assertEquals(value, "bar");
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:30,代码来源:DynamicLinkerFactoryTest.java

示例8: setupTest

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
@BeforeClass
public void setupTest() {
    engine = new ScriptEngineManager().getEngineByName("js");
    engine.put("f", new AbstractJSObject() {
        @Override
        public boolean isFunction() {
            return true;
        }
        @Override
        public Object call(Object thiz, Object... args) {
            return Arrays.deepToString(args);
        }
    });
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:15,代码来源:JDK_8148140_Test.java

示例9: bindCursor

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
protected void bindCursor(JSObject aModelData) {
    if (aModelData != null) {
        boundToCursor = Scripts.getSpace().listen(aModelData, cursorProperty, new AbstractJSObject() {

            @Override
            public Object call(Object thiz, Object... args) {
                ModelGrid.this.invalidate();
                ModelGrid.this.repaint();
                return null;
            }

        });
    }
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:15,代码来源:ModelGrid.java

示例10: bind

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
protected void bind() {
    if (data != null && Scripts.isInitialized()) {
        boundToData = Scripts.getSpace().listen(data, "length", new AbstractJSObject() {

            @Override
            public Object call(Object thiz, Object... args) {
                enqueueElementsChanged();
                return null;
            }

        });
    }
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:14,代码来源:ArrayModel.java

示例11: bind

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
protected void bind() {
    if (data != null && field != null && !field.isEmpty() && Scripts.isInitialized()) {
        boundToData = Scripts.getSpace().listen(data, field, new AbstractJSObject() {

            @Override
            public Object call(Object thiz, Object... args) {
                rebind();
                return null;
            }

        });
        Object oData = ModelWidget.getPathData(data, field);
        setJsValue(oData);
        boundToValue = (PropertyChangeEvent evt) -> {
            if (!settingValueFromJs) {
                settingValueToJs = true;
                try {
                    ModelWidget.setPathData(data, field, Scripts.getSpace().toJs(evt.getNewValue()));
                } finally {
                    settingValueToJs = false;
                }
            }
        };
        addValueChangeListener(boundToValue);
    } else {
        setJsValue(null);
    }
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:29,代码来源:ModelComponentDecorator.java

示例12: bindList

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
protected void bindList() {
    if (displayList != null && Scripts.isInitialized()) {
        boundToList = Scripts.getSpace().listen(displayList, "length", new AbstractJSObject() {

            @Override
            public Object call(Object thiz, Object... args) {
                enqueueListChanged();
                return null;
            }

        });
    }
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:14,代码来源:ModelCombo.java

示例13: setPublished

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
@Override
public void setPublished(JSObject aValue) {
    if (published != null && Scripts.isInitialized()) {
        throw new AlreadyPublishedException();
    }
    published = aValue;
    if (Scripts.isInitialized()) {
        Scripts.getSpace().listen(published, "cursor", new AbstractJSObject() {

            @Override
            public boolean isFunction() {
                return true;
            }

            @Override
            public Object call(Object thiz, Object... args) {
                try {
                    resignOnCursor();
                    internalExecuteChildren(false);
                } catch (Exception ex) {
                    Logger.getLogger(ApplicationEntity.class.getName()).log(Level.SEVERE, null, ex);
                }
                return null;
            }

        });
    }
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:29,代码来源:ApplicationEntity.java

示例14: resignOnCursor

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
protected void resignOnCursor() {
    if (cursorListener != null) {
        cursorListener.remove();
        cursorListener = null;
    }
    if (published != null && published.getMember(CURSOR_PROP_NAME) instanceof JSObject) {
        JSObject jsCursor = (JSObject) published.getMember(CURSOR_PROP_NAME);
        JSObject jsReg = Scripts.getSpace().listen(jsCursor, "", new AbstractJSObject() {

            @Override
            public boolean isFunction() {
                return true;
            }

            @Override
            public Object call(Object thiz, Object... args) {
                try {
                    internalExecuteChildren(false);
                } catch (Exception ex) {
                    Logger.getLogger(ApplicationEntity.class.getName()).log(Level.SEVERE, null, ex);
                }
                return null;
            }

        });
        cursorListener = () -> {
            Scripts.unlisten(jsReg);
        };
    }
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:31,代码来源:ApplicationEntity.java

示例15: getDefaultValue

import jdk.nashorn.api.scripting.AbstractJSObject; //导入依赖的package包/类
/**
 * Implements this object's {@code [[DefaultValue]]} method by returning its wrapped object's {@code [[DefaultValue]]}.
 *
 * @param hint the type hint. Should be either {@code null}, {@code Number.class} or {@code String.class}.
 * @return the wrapped object's default value.
 * @throws UnsupportedOperationException if the conversion can't be performed. The engine will convert this
 * exception into a JavaScript {@code TypeError}.
 */
public Object getDefaultValue(final Class<?> hint) {
    return AbstractJSObject.getDefaultValue(obj, hint);
}
 
开发者ID:malaporte,项目名称:kaziranga,代码行数:12,代码来源:JSONListAdapter.java


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