MCPcopy Create free account
hub / github.com/dynjs/dynjs / Types

Class Types

src/main/java/org/dynjs/runtime/Types.java:12–762  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10import org.dynjs.runtime.builtins.types.string.DynString;
11
12public class Types {
13
14 public static final Undefined UNDEFINED = new Undefined();
15 public static final Null NULL = new Null();
16
17 public static void checkObjectCoercible(ExecutionContext context, Object o) {
18 if (o == Types.UNDEFINED) {
19 throw new ThrowException(context, context.createTypeError("undefined cannot be coerced to an object"));
20 }
21
22 if (o == Types.NULL) {
23 throw new ThrowException(context, context.createTypeError("null cannot be coerced to an object"));
24 }
25
26 return;
27 }
28
29 public static void checkObjectCoercible(ExecutionContext context, Object o, String debug) {
30 if (o == Types.UNDEFINED) {
31 throw new ThrowException(context, context.createTypeError("undefined cannot be coerced to an object: " + debug));
32 }
33
34 if (o == Types.NULL) {
35 throw new ThrowException(context, context.createTypeError("null cannot be coerced to an object: " + debug));
36 }
37
38 return;
39 }
40
41 public static boolean sameValue(Object left, Object right) {
42
43 if (left.getClass() != right.getClass()) {
44 return false;
45 }
46
47 if (left == UNDEFINED) {
48 return true;
49 }
50
51 if (left == NULL) {
52 return true;
53 }
54
55 return left.equals(right);
56 }
57
58 public static JSObject toObject(ExecutionContext context, Object o) {
59 if (o == Types.UNDEFINED) {
60 throw new ThrowException(context, context.createTypeError("undefined cannot be converted to an object"));
61 }
62 if (o == Types.NULL) {
63 throw new ThrowException(context, context.createTypeError("null cannot be converted to an object"));
64 }
65 if (o instanceof JSObject) {
66 return (JSObject) o;
67 }
68 if (o instanceof String) {
69 return new DynString(context.getGlobalContext(), (String) o);

Callers

nothing calls this directly

Calls 1

compileMethod · 0.65

Tested by

no test coverage detected