Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Map and Set to use lambdas #1800

Merged
merged 9 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,19 @@ static Map<Object, List<Object>> groupBy(
Object items,
Object callback,
KEY_COERCION keyCoercion) {
return groupBy(cx, scope, f.getTag(), f.getFunctionName(), items, callback, keyCoercion);
}

static Map<Object, List<Object>> groupBy(
Context cx,
Scriptable scope,
Object classTag,
String functionName,
Object items,
Object callback,
KEY_COERCION keyCoercion) {
if (cx.getLanguageVersion() >= Context.VERSION_ES6) {
ScriptRuntimeES6.requireObjectCoercible(cx, items, f);
ScriptRuntimeES6.requireObjectCoercible(cx, items, classTag, functionName);
}
if (!(callback instanceof Callable)) {
throw ScriptRuntime.typeErrorById(
Expand Down
30 changes: 30 additions & 0 deletions rhino/src/main/java/org/mozilla/javascript/LambdaConstructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ public void definePrototypeProperty(Symbol key, Object value, int attributes) {
proto.defineProperty(key, value, attributes);
}

public void definePrototypeProperty(Context cx, String name, ScriptableObject descriptor) {
ScriptableObject proto = getPrototypeScriptable();
proto.defineOwnProperty(cx, name, descriptor);
}

public void definePrototypeProperty(Context cx, Symbol key, ScriptableObject descriptor) {
ScriptableObject proto = getPrototypeScriptable();
proto.defineOwnProperty(cx, key, descriptor);
}

/**
* Define a property on the prototype using a function. The function will be wired to a
* JavaScript function, so the resulting property will look just like one that was defined using
Expand All @@ -203,6 +213,12 @@ public void definePrototypeProperty(
proto.defineProperty(cx, name, getter, null, attributes);
}

public void definePrototypeProperty(
Context cx, Symbol key, ScriptableObject.LambdaGetterFunction getter, int attributes) {
ScriptableObject proto = getPrototypeScriptable();
proto.defineProperty(cx, key, getter, null, attributes);
}

/**
* Define a property on the prototype using functions for getter and setter. The function will
* be wired to a JavaScript function, so the resulting property will look just like one that was
Expand All @@ -218,6 +234,20 @@ public void definePrototypeProperty(
proto.defineProperty(cx, name, getter, setter, attributes);
}

/** Define a property on the prototype that has the same value as another property. */
public void definePrototypeAlias(String name, SymbolKey alias, int attributes) {
ScriptableObject proto = getPrototypeScriptable();
Object val = proto.get(name, proto);
proto.defineProperty(alias, val, attributes);
}

/** Define a property on the prototype that has the same value as another property. */
public void definePrototypeAlias(String name, String alias, int attributes) {
ScriptableObject proto = getPrototypeScriptable();
Object val = proto.get(name, proto);
proto.defineProperty(alias, val, attributes);
}

/**
* Define a function property directly on the constructor that is implemented under the covers
* by a LambdaFunction.
Expand Down
Loading