scriptable 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/evaluate.js +14 -5
  2. package/package.json +1 -1
package/dist/evaluate.js CHANGED
@@ -15,6 +15,15 @@ function assertSafeProperty(prop) {
15
15
  throw new Error(`Access to property '${prop}' is not allowed`);
16
16
  }
17
17
  }
18
+ function toPropertyKey(value) {
19
+ if (value !== null &&
20
+ (typeof value === "object" ||
21
+ typeof value === "function" ||
22
+ typeof value === "symbol")) {
23
+ throw new Error("Property key must be a primitive value");
24
+ }
25
+ return String(value);
26
+ }
18
27
  // Sentinel thrown by ReturnStatement and caught at the nearest function
19
28
  // boundary (makeFunc). Without this, a `return` nested inside an `if` (or
20
29
  // any non-ReturnStatement node) would be evaluated but the enclosing
@@ -45,7 +54,7 @@ function evalAsPath(exp, env, functions) {
45
54
  if (exp.type === "MemberExpression") {
46
55
  const objParts = evalAsPath(exp.object, env, functions);
47
56
  const propStr = exp.computed
48
- ? String(evaluate(exp.property, env, functions))
57
+ ? toPropertyKey(evaluate(exp.property, env, functions))
49
58
  : String(exp.property.name);
50
59
  assertSafeProperty(propStr);
51
60
  return [...objParts, propStr];
@@ -242,9 +251,9 @@ const evals = {
242
251
  MemberExpression(exp, env, functions) {
243
252
  const obj = evaluate(exp.object, env, functions);
244
253
  if (exp.computed) {
245
- const prop = evaluate(exp.property, env, functions);
246
- assertSafeProperty(String(prop));
247
- return obj[prop];
254
+ const key = toPropertyKey(evaluate(exp.property, env, functions));
255
+ assertSafeProperty(key);
256
+ return obj[key];
248
257
  }
249
258
  const prop = evaluate(exp.property);
250
259
  assertSafeProperty(prop);
@@ -285,7 +294,7 @@ const evals = {
285
294
  // silently used the identifier NAME "k" instead of its value.
286
295
  let key;
287
296
  if (prop.computed) {
288
- key = String(evaluate(prop.key, env, functions));
297
+ key = toPropertyKey(evaluate(prop.key, env, functions));
289
298
  }
290
299
  else if (prop.key.type === "Identifier") {
291
300
  key = prop.key.name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scriptable",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",