package com.oracle.truffle.js.nodes.access;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.js.nodes.JavaScriptBaseNode;
import com.oracle.truffle.js.runtime.BigInt;
import com.oracle.truffle.js.runtime.JSConfig;
import com.oracle.truffle.js.runtime.SafeInteger;
import com.oracle.truffle.js.runtime.Symbol;
@ImportStatic({JSConfig.class})
public abstract class IsPrimitiveNode extends JavaScriptBaseNode {
public abstract boolean executeBoolean(Object operand);
@Specialization(guards = {"isJSNull(operand)"})
protected static boolean doNull(@SuppressWarnings("unused") Object operand) {
return true;
}
@Specialization(guards = {"isUndefined(operand)"})
protected static boolean doUndefined(@SuppressWarnings("unused") Object operand) {
return true;
}
@Specialization
protected static boolean doBoolean(@SuppressWarnings("unused") boolean operand) {
return true;
}
@Specialization
protected static boolean doInt(@SuppressWarnings("unused") int operand) {
return true;
}
@Specialization
protected static boolean doLong(@SuppressWarnings("unused") long operand) {
return true;
}
@Specialization
protected static boolean doLargeInt(@SuppressWarnings("unused") SafeInteger operand) {
return true;
}
@Specialization
protected static boolean doDouble(@SuppressWarnings("unused") double operand) {
return true;
}
@Specialization
protected static boolean doSymbol(@SuppressWarnings("unused") Symbol operand) {
return true;
}
@Specialization
protected static boolean doBigInt(@SuppressWarnings("unused") BigInt operand) {
return true;
}
@Specialization
protected static boolean doString(@SuppressWarnings("unused") CharSequence operand) {
return true;
}
@SuppressWarnings("unused")
@Specialization(guards = {"isJSObject(operand)"})
protected static boolean doIsObject(DynamicObject operand) {
return false;
}
@Specialization(guards = {"isForeignObject(operand)"}, limit = "InteropLibraryLimit")
protected static boolean doForeignObject(Object operand,
@CachedLibrary("operand") InteropLibrary interop) {
if (interop.isNull(operand)) {
return true;
} else if (interop.isBoolean(operand)) {
return true;
} else if (interop.isString(operand)) {
return true;
} else if (interop.isNumber(operand)) {
return true;
}
return false;
}
public static IsPrimitiveNode create() {
return IsPrimitiveNodeGen.create();
}
}