org.mozilla.javascript.ScriptableObject.putProperty()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 JavaScript  
字(7.8k)|赞(0)|评价(0)|浏览(227)

本文整理了Java中org.mozilla.javascript.ScriptableObject.putProperty()方法的一些代码示例,展示了ScriptableObject.putProperty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ScriptableObject.putProperty()方法的具体详情如下:
包路径:org.mozilla.javascript.ScriptableObject
类名称:ScriptableObject
方法名:putProperty

ScriptableObject.putProperty介绍

[英]Puts an indexed property in an object or in an object in its prototype chain.

Searches for the indexed property in the prototype chain. If it is found, the value of the property in obj is changed through a call to Scriptable#put(int,Scriptable,Object) on the prototype passing obj as the start argument. This allows the prototype to veto the property setting in case the prototype defines the property with ReadOnly attribute. If the property is not found, it is added in obj.
[中]将索引属性放入对象或其原型链中的对象中。
在原型链中搜索索引属性。如果找到它,obj中属性的值将通过调用原型上的Scriptable#put(int,Scriptable,Object)来更改,并将obj作为start参数传递。如果原型使用ReadOnly属性定义属性,则原型可以否决属性设置。如果找不到该属性,则将其添加到obj

代码示例

代码示例来源:origin: facebook/stetho

private void importFunctions(@NonNull ScriptableObject scope) throws StethoJsException {
 // Define the functions
 for (Map.Entry<String, Function> entrySet : mFunctions.entrySet()) {
  String functionName = entrySet.getKey();
  Function function = entrySet.getValue();
  try {
   ScriptableObject.putProperty(scope, functionName, function);
  } catch (Exception e) {
   throw new StethoJsException(e, "Failed to setup function: %s", functionName);
  }
 }
}

代码示例来源:origin: galenframework/galen

public void putObject(String name, Object object) {
  ScriptableObject.putProperty(scope, name, Context.javaToJS(object, scope));
}

代码示例来源:origin: facebook/stetho

private void importVariables(@NonNull ScriptableObject scope) throws StethoJsException {
 // Define the variables
 for (Map.Entry<String, Object> entrySet : mVariables.entrySet()) {
  String varName = entrySet.getKey();
  Object varValue = entrySet.getValue();
  try {
   Object jsValue;
   if (varValue instanceof Scriptable || varValue instanceof Undefined) {
    jsValue = varValue;
   } else {
    jsValue = Context.javaToJS(varValue, scope);
   }
   ScriptableObject.putProperty(scope, varName, jsValue);
  } catch (Exception e) {
   throw new StethoJsException(e, "Failed to setup variable: %s", varName);
  }
 }
}

代码示例来源:origin: facebook/stetho

@Override
public @Nullable Object evaluate(@NonNull String expression) throws Throwable {
  Object result;
  final Context jsContext = enterJsContext();
  try {
   result = jsContext.evaluateString(mJsScope, expression, "chrome", 1, null);
   // Google chrome automatically saves the last expression to `$_`, we do the same
   Object jsValue = Context.javaToJS(result, mJsScope);
   ScriptableObject.putProperty(mJsScope, "$_", jsValue);
  } finally {
   Context.exit();
  }
  return Context.jsToJava(result, Object.class);
}

代码示例来源:origin: facebook/stetho

private @NonNull ScriptableObject initJsScope(@NonNull Context jsContext) {
 // Set the main Rhino goodies
 ImporterTopLevel importerTopLevel = new ImporterTopLevel(jsContext);
 ScriptableObject scope = jsContext.initStandardObjects(importerTopLevel, false);
 ScriptableObject.putProperty(scope, "context", Context.javaToJS(mContext, scope));
 try {
  importClasses(jsContext, scope);
  importPackages(jsContext, scope);
  importConsole(scope);
  importVariables(scope);
  importFunctions(scope);
 } catch (StethoJsException e) {
  String message = String.format("%s\n%s", e.getMessage(), Log.getStackTraceString(e));
  LogUtil.e(e, message);
  CLog.writeToConsole(Console.MessageLevel.ERROR, Console.MessageSource.JAVASCRIPT, message);
 }
 return scope;
}

代码示例来源:origin: EngineHub/WorldEdit

ScriptableObject.putProperty(scope, entry.getKey(),
    Context.javaToJS(entry.getValue(), scope));

代码示例来源:origin: pentaho/pentaho-kettle

for ( int i = 0; i < getAddClasses().length; i++ ) {
 Object jsOut = Context.javaToJS( getAddClasses()[i].getAddObject(), jsscope );
 ScriptableObject.putProperty( jsscope, getAddClasses()[i].getJSName(), jsOut );

代码示例来源:origin: pentaho/pentaho-kettle

for ( int i = 0; i < input.getAddClasses().length; i++ ) {
 Object jsOut = Context.javaToJS( input.getAddClasses()[i].getAddObject(), jsscope );
 ScriptableObject.putProperty( jsscope, input.getAddClasses()[i].getJSName(), jsOut );

代码示例来源:origin: pentaho/pentaho-kettle

for ( int i = 0; i < input.getAddClasses().length; i++ ) {
 Object jsOut = Context.javaToJS( input.getAddClasses()[i].getAddObject(), jsscope );
 ScriptableObject.putProperty( jsscope, input.getAddClasses()[i].getJSName(), jsOut );

代码示例来源:origin: rnewson/couchdb-lucene

private Scriptable convertArray(final JSONArray array) throws JSONException {
  final Scriptable result = context.newArray(scope, array.length());
  for (int i = 0, max = array.length(); i < max; i++) {
    ScriptableObject.putProperty(result, i, convert(array.get(i)));
  }
  return result;
}

代码示例来源:origin: rnewson/couchdb-lucene

private Scriptable convertObject(final JSONObject obj) throws JSONException {
  if (obj == JSONObject.NULL) {
    return null;
  }
  final Scriptable result = context.newObject(scope);
  final Iterator<?> it = obj.keys();
  while (it.hasNext()) {
    final String key = (String) it.next();
    final Object value = obj.get(key);
    ScriptableObject.putProperty(result, key, convert(value));
  }
  return result;
}

代码示例来源:origin: rnewson/couchdb-lucene

public DocumentConverter(final Context context, final View view) throws IOException, JSONException {
  this.context = context;
  scope = context.initStandardObjects();
  context.setLanguageVersion(Context.VERSION_1_8);
  // Allow custom document helper class.
  try {
    ScriptableObject.defineClass(scope, RhinoDocument.class);
  } catch (IllegalAccessException e) {
    throw new RuntimeException(e);
  } catch (InstantiationException e) {
    throw new RuntimeException(e);
  } catch (InvocationTargetException e) {
    throw new RuntimeException(e);
  }
  // Add a log object
  ScriptableObject.putProperty(scope, "log", new JSLog());
  // Compile user-specified function
  try {
    viewFun = view.compileFunction(context, scope);
  } catch (final RhinoException e) {
    LOG.error("View code for " + view + " does not compile.");
    throw e;
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

for ( int i = 0; i < meta.getAddClasses().length; i++ ) {
 Object jsOut = Context.javaToJS( meta.getAddClasses()[ i ].getAddObject(), data.scope );
 ScriptableObject.putProperty( data.scope, meta.getAddClasses()[ i ].getJSName(), jsOut );

代码示例来源:origin: geogebra/geogebra

/**
 * Binds this instance of require() into the specified scope under the
 * property name "require".
 * @param scope the scope where the require() function is to be installed.
 */
public void install(Scriptable scope) {
  ScriptableObject.putProperty(scope, "require", this);
}

代码示例来源:origin: geogebra/geogebra

private static void setElem(Context cx, Scriptable target, long index,
              Object value)
{
  if (index > Integer.MAX_VALUE) {
    String id = Long.toString(index);
    ScriptableObject.putProperty(target, id, value);
  } else {
    ScriptableObject.putProperty(target, (int)index, value);
  }
}

代码示例来源:origin: rhino/js

static void init(Scriptable scope, boolean sealed)
{
  NativeError obj = new NativeError();
  ScriptableObject.putProperty(obj, "name", "Error");
  ScriptableObject.putProperty(obj, "message", "");
  ScriptableObject.putProperty(obj, "fileName", "");
  ScriptableObject.putProperty(obj, "lineNumber", new Integer(0));
  obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
}

代码示例来源:origin: rhino/js

public static Object setObjectProp(Scriptable obj, String property,
                  Object value, Context cx)
{
  if (obj instanceof XMLObject) {
    XMLObject xmlObject = (XMLObject)obj;
    xmlObject.ecmaPut(cx, property, value);
  } else {
    ScriptableObject.putProperty(obj, property, value);
  }
  return value;
}

代码示例来源:origin: geogebra/geogebra

private static void defineReadOnlyProperty(ScriptableObject obj,
    String name, Object value) {
  ScriptableObject.putProperty(obj, name, value);
  obj.setAttributes(name, ScriptableObject.READONLY |
      ScriptableObject.PERMANENT);
}

代码示例来源:origin: ro.isdc.wro4j/rhino

private static void defineReadOnlyProperty(ScriptableObject obj,
    String name, Object value) {
  ScriptableObject.putProperty(obj, name, value);
  obj.setAttributes(name, ScriptableObject.READONLY |
      ScriptableObject.PERMANENT);
}

代码示例来源:origin: com.sun.phobos/phobos-rhino

public static Object setObjectProp(Scriptable obj, String property,
                  Object value, Context cx)
{
  if (obj instanceof XMLObject) {
    XMLObject xmlObject = (XMLObject)obj;
    xmlObject.ecmaPut(cx, property, value);
  } else {
    ScriptableObject.putProperty(obj, property, value);
  }
  return value;
}

相关文章

微信公众号

ScriptableObject类方法