Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
Rhino JavaScript Java Library Source Code
Rhino JavaScript Java Library is an open-source implementation of JavaScript
written entirely in Java.
Rhino JavaScript Java Library Source Code files are provided in binary package (rhino-1.7.14.zip).
You can also browse the source code below:
✍: FYIcenter.com
⏎ org/mozilla/javascript/IteratorLikeIterable.java
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.javascript;
import java.io.Closeable;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* This is a class that makes it easier to iterate over "iterator-like" objects as defined in the
* ECMAScript spec. The caller is responsible for retrieving an object that implements the
* "iterator" pattern. This class will follow that pattern and throw appropriate JavaScript
* exceptions.
*
* <p>The pattern that the target class should follow is: * It must have a function property called
* "next" * The function must return an object with a boolean value called "done". * If "done" is
* true, then the returned object should also contain a "value" property. * If it has a function
* property called "return" then it will be called when the caller is done iterating.
*/
public class IteratorLikeIterable implements Iterable<Object>, Closeable {
private final Context cx;
private final Scriptable scope;
private final Callable next;
private final Callable returnFunc;
private final Scriptable iterator;
private boolean closed;
public IteratorLikeIterable(Context cx, Scriptable scope, Object target) {
this.cx = cx;
this.scope = scope;
// This will throw if "next" is not a function or undefined
next = ScriptRuntime.getPropFunctionAndThis(target, ES6Iterator.NEXT_METHOD, cx, scope);
iterator = ScriptRuntime.lastStoredScriptable(cx);
Object retObj =
ScriptRuntime.getObjectPropNoWarn(target, ES6Iterator.RETURN_PROPERTY, cx, scope);
// We only care about "return" if it is not null or undefined
if ((retObj != null) && !Undefined.isUndefined(retObj)) {
if (!(retObj instanceof Callable)) {
throw ScriptRuntime.notFunctionError(target, retObj, ES6Iterator.RETURN_PROPERTY);
}
returnFunc = (Callable) retObj;
} else {
returnFunc = null;
}
}
@Override
public void close() {
if (!closed) {
closed = true;
if (returnFunc != null) {
returnFunc.call(cx, scope, iterator, ScriptRuntime.emptyArgs);
}
}
}
@Override
public Itr iterator() {
return new Itr();
}
public final class Itr implements Iterator<Object> {
private Object nextVal;
private boolean isDone;
@Override
public boolean hasNext() {
if (isDone) {
return false;
}
Object val = next.call(cx, scope, iterator, ScriptRuntime.emptyArgs);
// This will throw if "val" is not an object.
// "getObjectPropNoWarn" won't, so do this as follows.
Object doneval =
ScriptableObject.getProperty(
ScriptableObject.ensureScriptable(val), ES6Iterator.DONE_PROPERTY);
if (doneval == Scriptable.NOT_FOUND) {
doneval = Undefined.instance;
}
// It's OK if done is undefined.
if (ScriptRuntime.toBoolean(doneval)) {
isDone = true;
return false;
}
nextVal = ScriptRuntime.getObjectPropNoWarn(val, ES6Iterator.VALUE_PROPERTY, cx, scope);
return true;
}
@Override
public Object next() {
if (isDone) {
throw new NoSuchElementException();
}
return nextVal;
}
/** Find out if "hasNext" returned done without invoking the function again. */
public boolean isDone() {
return isDone;
}
/** Manually set "done." Used for exception handling in promises. */
public void setDone(boolean done) {
this.isDone = done;
}
}
}
⏎ org/mozilla/javascript/IteratorLikeIterable.java
Or download all of them as a single archive file:
File name: rhino-1.7.14-sources.jar File size: 1029165 bytes Release date: 2022-01-06 Download
⇒ Example code to Test rhino-runtime-1.7.14.jar
⇐ Download Rhino JavaScript Binary Package
2022-05-03, ≈142🔥, 1💬
Popular Posts:
What Is fop.jar? I got it from the fop-2.7-bin.zip. fop.jar in fop-2.7-bin.zip is the JAR file for F...
Snappy-Java is a Java port of the "snappy", a fast C++ compresser/decompresser developed by Google. ...
maven-compat-3.5.4.jar is the JAR file for Apache Maven 3.5.4 Compact module. The JAR file name may ...
The JDT project provides the tool plug-ins that implement a Java IDE supporting the development of a...
JDK 11 jdk.rmic.jmod is the JMOD file for JDK 11 RMI (Remote Method Invocation) Compiler Tool tool, ...