Skip to content

Commit

Permalink
Mozilla Rhino 1.75
Browse files Browse the repository at this point in the history
  • Loading branch information
oswetto committed May 5, 2024
1 parent 729af34 commit 0ae256b
Show file tree
Hide file tree
Showing 70 changed files with 12,461 additions and 11,927 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,22 @@ ScriptableObject getPropertyDescriptor(Context cx, Scriptable scope) {
// It sounds logical that this would be the same as the logic for a normal Slot,
// but the spec is super pedantic about things like the order of properties here,
// so we need special support here.

ScriptableObject desc = (ScriptableObject) cx.newObject(scope);
desc.setCommonDescriptorProperties(getAttributes(), getter == null && setter == null);
int attr = getAttributes();

boolean es6 = cx.getLanguageVersion() >= Context.VERSION_ES6;
if (es6) {
if (getter == null && setter == null) {
desc.defineProperty(
"writable",
(attr & ScriptableObject.READONLY) == 0,
ScriptableObject.EMPTY);
}
} else {
desc.setCommonDescriptorProperties(attr, getter == null && setter == null);
}

String fName = name == null ? "f" : name.toString();
if (getter != null) {
Function f = getter.asGetterFunction(fName, scope);
Expand All @@ -42,7 +56,19 @@ ScriptableObject getPropertyDescriptor(Context cx, Scriptable scope) {
if (setter != null) {
Function f = setter.asSetterFunction(fName, scope);
desc.defineProperty("set", f == null ? Undefined.instance : f, ScriptableObject.EMPTY);
} else if (es6) {
desc.defineProperty("set", Undefined.instance, ScriptableObject.EMPTY);
}

if (es6) {
desc.defineProperty(
"enumerable", (attr & ScriptableObject.DONTENUM) == 0, ScriptableObject.EMPTY);
desc.defineProperty(
"configurable",
(attr & ScriptableObject.PERMANENT) == 0,
ScriptableObject.EMPTY);
}

return desc;
}

Expand Down
26 changes: 7 additions & 19 deletions LoboParser/src/main/java/org/mozilla/javascript/Arguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package org.mozilla.javascript;

import org.mozilla.javascript.NativeArrayIterator.ARRAY_ITERATOR_TYPE;

/**
* This class implements the "arguments" object.
*
Expand Down Expand Up @@ -41,7 +39,12 @@ public Arguments(NativeCall activation) {
callerObj = NOT_FOUND;
}

defineProperty(SymbolKey.ITERATOR, iteratorMethod, ScriptableObject.DONTENUM);
defineProperty(
SymbolKey.ITERATOR,
TopLevel.getBuiltinPrototype(
ScriptableObject.getTopLevelScope(parent), TopLevel.Builtins.Array)
.get("values", parent),
ScriptableObject.DONTENUM);
}

@Override
Expand Down Expand Up @@ -402,28 +405,13 @@ void defineAttributesForStrictMode() {
calleeObj = null;
}

private static BaseFunction iteratorMethod =
new BaseFunction() {
private static final long serialVersionUID = 4239122318596177391L;

@Override
public Object call(
Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
// TODO : call %ArrayProto_values%
// 9.4.4.6 CreateUnmappedArgumentsObject(argumentsList)
// 1. Perform DefinePropertyOrThrow(obj, @@iterator, PropertyDescriptor
// {[[Value]]:%ArrayProto_values%,
// [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}).
return new NativeArrayIterator(scope, thisObj, ARRAY_ITERATOR_TYPE.VALUES);
}
};

private static class ThrowTypeError extends BaseFunction {
private static final long serialVersionUID = -744615873947395749L;
private String propertyName;

ThrowTypeError(String propertyName) {
this.propertyName = propertyName;
super.setInstanceIdAttributes(BaseFunction.Id_name, PERMANENT | READONLY | DONTENUM);
}

@Override
Expand Down
14 changes: 11 additions & 3 deletions LoboParser/src/main/java/org/mozilla/javascript/BaseFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public boolean hasInstance(Scriptable instance) {
throw ScriptRuntime.typeErrorById("msg.instanceof.bad.prototype", getFunctionName());
}

private static final int Id_length = 1,
protected static final int Id_length = 1,
Id_arity = 2,
Id_name = 3,
Id_prototype = 4,
Expand Down Expand Up @@ -169,7 +169,9 @@ protected Object getInstanceIdValue(int id) {
case Id_arity:
return arityPropertyAttributes >= 0 ? getArity() : NOT_FOUND;
case Id_name:
return namePropertyAttributes >= 0 ? getFunctionName() : NOT_FOUND;
return namePropertyAttributes >= 0
? (nameValue != null ? nameValue : getFunctionName())
: NOT_FOUND;
case Id_prototype:
return getPrototypeProperty();
case Id_arguments:
Expand Down Expand Up @@ -200,6 +202,11 @@ protected void setInstanceIdValue(int id, Object value) {
case Id_name:
if (value == NOT_FOUND) {
namePropertyAttributes = -1;
nameValue = null;
} else if (value instanceof CharSequence) {
nameValue = ScriptRuntime.toString(value);
} else {
nameValue = "";
}
return;
case Id_arity:
Expand Down Expand Up @@ -650,6 +657,7 @@ protected int findPrototypeId(String s) {

private Object prototypeProperty;
private Object argumentsObj = NOT_FOUND;
private String nameValue = null;
private boolean isGeneratorFunction = false;

// For function object instances, attributes are
Expand All @@ -658,6 +666,6 @@ protected int findPrototypeId(String s) {
private int prototypePropertyAttributes = PERMANENT | DONTENUM;
private int argumentsAttributes = PERMANENT | DONTENUM;
private int arityPropertyAttributes = PERMANENT | READONLY | DONTENUM;
private int namePropertyAttributes = PERMANENT | READONLY | DONTENUM;
private int namePropertyAttributes = READONLY | DONTENUM;
private int lengthPropertyAttributes = PERMANENT | READONLY | DONTENUM;
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ private void generateICodeFromTree(Node tree) {
itsData.argNames = scriptOrFn.getParamAndVarNames();
itsData.argIsConst = scriptOrFn.getParamAndVarConst();
itsData.argCount = scriptOrFn.getParamCount();
itsData.argsHasRest = scriptOrFn.hasRestParameter();

itsData.encodedSourceStart = scriptOrFn.getEncodedSourceStart();
itsData.encodedSourceEnd = scriptOrFn.getEncodedSourceEnd();
Expand Down
12 changes: 7 additions & 5 deletions LoboParser/src/main/java/org/mozilla/javascript/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,12 @@ public static void exit() {

@Override
public void close() {
exit();
if (enterCount < 1) Kit.codeBug();
if (--enterCount == 0) {
Object helper = VMBridge.instance.getThreadContextHelper();
VMBridge.instance.setContext(helper, null);
factory.onContextReleased(this);
}
}

/**
Expand Down Expand Up @@ -539,11 +544,8 @@ public static Object call(

/** The method implements {@link ContextFactory#call(ContextAction)} logic. */
static <T> T call(ContextFactory factory, ContextAction<T> action) {
Context cx = enter(null, factory);
try {
try (Context cx = enter(null, factory)) {
return action.run(cx);
} finally {
exit();
}
}

Expand Down
18 changes: 16 additions & 2 deletions LoboParser/src/main/java/org/mozilla/javascript/Decompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,22 @@ int getCurrentOffset() {
return sourceTop;
}

int markFunctionStart(int functionType) {
int markFunctionStart(int functionType, boolean isGenerator) {
int savedOffset = getCurrentOffset();
if (functionType != FunctionNode.ARROW_FUNCTION) {
addToken(Token.FUNCTION);
if (isGenerator) addToken(Token.MUL);
append((char) functionType);
}
return savedOffset;
}

/** @deprecated use {@link #markFunctionStart(int, boolean)} instead */
@Deprecated
int markFunctionStart(int functionType) {
return markFunctionStart(functionType, false);
}

int markFunctionEnd(int functionStart) {
int offset = getCurrentOffset();
append((char) FUNCTION_END);
Expand Down Expand Up @@ -342,7 +349,10 @@ public static String decompile(String source, int flags, UintMap properties) {

case Token.FUNCTION:
++i; // skip function type
result.append("function ");
if (source.charAt(i) == Token.MUL) {
result.append("function* ");
++i;
} else result.append("function ");
break;

case FUNCTION_END:
Expand Down Expand Up @@ -784,6 +794,10 @@ else if (nextToken == Token.NAME) {
i = printSourceString(source, i + 1, false, result);
continue;

case Token.DOTDOTDOT:
result.append("...");
break;

default:
// If we don't know how to decompile it, raise an exception.
throw new RuntimeException("Token: " + Token.name(source.charAt(i)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Delegator(Scriptable obj) {
*/
protected Delegator newInstance() {
try {
return this.getClass().newInstance();
return this.getClass().getDeclaredConstructor().newInstance();
} catch (Exception ex) {
throw Context.throwAsScriptRuntimeEx(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public Scriptable createObject(Context cx, Scriptable scope) {
}
Scriptable result;
try {
result = (Scriptable) member.getDeclaringClass().newInstance();
result = (Scriptable) member.getDeclaringClass().getDeclaredConstructor().newInstance();
} catch (Exception ex) {
throw Context.throwAsScriptRuntimeEx(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public void clear() {
map.clear();
}

@Override
public Iterator<Entry> iterator() {
return new Iter(first);
}
Expand Down

0 comments on commit 0ae256b

Please sign in to comment.