Skip to content

Commit

Permalink
Allow using Intl in bindings (#2586)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Aug 30, 2023
1 parent 6e0e299 commit 2d406b4
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 84 deletions.
2 changes: 1 addition & 1 deletion packages/toolpad-core/src/jsBrowserRuntime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function createBrowserRuntime(): JsRuntime {
(() => {
// See https://tc39.es/ecma262/multipage/global-object.html#sec-global-object
const ecmaGlobals = new Set([ 'globalThis', 'Infinity', 'NaN', 'undefined', 'eval', 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'AggregateError', 'Array', 'ArrayBuffer', 'BigInt', 'BigInt64Array', 'BigUint64Array', 'Boolean', 'DataView', 'Date', 'Error', 'EvalError', 'FinalizationRegistry', 'Float32Array', 'Float64Array', 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Number', 'Object', 'Promise', 'Proxy', 'RangeError', 'ReferenceError', 'RegExp', 'Set', 'SharedArrayBuffer', 'String', 'Symbol', 'SyntaxError', 'TypeError', 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'URIError', 'WeakMap', 'WeakRef', 'WeakSet', 'Atomics', 'JSON', 'Math', 'Reflect' ]);
const allowedDomGlobals = new Set([ 'setTimeout', 'console', 'URL', 'URLSearchParams' ])
const allowedDomGlobals = new Set([ 'setTimeout', 'console', 'URL', 'URLSearchParams', 'Intl' ])
// NOTE: This is by no means intended to be a secure way to hide DOM globals
const globalThis = new Proxy(window.__SCOPE, {
Expand Down
38 changes: 19 additions & 19 deletions test/integration/bindings/fixture/toolpad/pages/bindings/page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ spec:
id: 741rda6
title: Page 1
content:
- component: PageRow
name: pageRow
children:
- component: Text
name: text
props:
value: -test1-
sx:
$$jsExpression: |
{ color: "primary.main", p: 2 }
- component: PageRow
name: pageRow1
children:
- component: Text
name: text1
props:
sx:
$$jsExpression: "{"
value: -test2-
- component: Text
name: text
children: []
layout:
columnSize: 1
props:
value: -test1-
sx:
$$jsExpression: |
{ color: "primary.main", p: 2 }
- component: Text
name: text1
children: []
layout:
columnSize: 1
props:
sx:
$$jsExpression: "{"
value: -test2-
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ spec:
value:
$$jsExpression: |
`Can pass utf-8: "€"`
children: []
- component: Text
name: text
name: text1
props:
value: 'Can pass double dollars: "$$"'
children: []
135 changes: 72 additions & 63 deletions test/integration/bindings/fixture/toolpad/pages/globalScope/page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,75 @@ spec:
title: globalScope
display: shell
content:
- component: PageRow
name: pageRow5
children:
- component: Text
name: text5
props:
variant: h2
value: "Bindings: global scope access"
- component: PageRow
name: pageRow
children:
- component: Text
name: text
props:
value:
$$jsExpression: |
`Allows ecmascript globals |test1 ${
typeof Array !== "undefined" ? "ok" : "nok"
}|`
- component: PageRow
name: pageRow1
children:
- component: Text
name: text1
props:
value:
$$jsExpression: |
`Disallows DOM globals |test2 ${
typeof document === "undefined" ? "ok" : "nok"
}|`
- component: PageRow
name: pageRow2
children:
- component: Text
name: text2
props:
value:
$$jsExpression: |
`Supports globalThis |test3 ${
typeof globalThis !== "undefined" ? "ok" : "nok"
}|`
- component: PageRow
name: pageRow3
children:
- component: Text
name: text3
props:
value:
$$jsExpression: |
`Disallows localStorage globals |test4 ${
typeof localStorage === "undefined" ? "ok" : "nok"
}|`
- component: PageRow
name: pageRow4
children:
- component: Text
name: text4
props:
value:
$$jsExpression: |
`Disallows globalThis.localStorage |test5 ${
typeof globalThis.localStorage === "undefined" ? "ok" : "nok"
}|`
- component: Text
name: text5
children: []
layout:
columnSize: 1
props:
variant: h2
value: "Bindings: global scope access"
- component: Text
name: text
children: []
layout:
columnSize: 1
props:
value:
$$jsExpression: |
`Allows ecmascript globals |test1 ${
typeof Array !== "undefined" ? "ok" : "nok"
}|`
- component: Text
name: text1
children: []
layout:
columnSize: 1
props:
value:
$$jsExpression: |
`Disallows DOM globals |test2 ${
typeof document === "undefined" ? "ok" : "nok"
}|`
- component: Text
name: text2
children: []
layout:
columnSize: 1
props:
value:
$$jsExpression: |
`Supports globalThis |test3 ${
typeof globalThis !== "undefined" ? "ok" : "nok"
}|`
- component: Text
name: text3
children: []
layout:
columnSize: 1
props:
value:
$$jsExpression: |
`Disallows localStorage globals |test4 ${
typeof localStorage === "undefined" ? "ok" : "nok"
}|`
- component: Text
name: text4
children: []
layout:
columnSize: 1
props:
value:
$$jsExpression: |
`Disallows globalThis.localStorage |test5 ${
typeof globalThis.localStorage === "undefined" ? "ok" : "nok"
}|`
- component: Text
name: text6
children: []
props:
value:
$$jsExpression: |
`Allows Intl |test6 ${
typeof Intl?.NumberFormat !== "undefined" ? "ok" : "nok"
}|`
1 change: 1 addition & 0 deletions test/integration/bindings/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ test('global scope', async ({ page }) => {
await expect(page.getByText('|test3 ok|')).toBeVisible();
await expect(page.getByText('|test4 ok|')).toBeVisible();
await expect(page.getByText('|test5 ok|')).toBeVisible();
await expect(page.getByText('|test6 ok|')).toBeVisible();
});

test('encoding', async ({ page }) => {
Expand Down

0 comments on commit 2d406b4

Please sign in to comment.