Skip to content
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
13 changes: 13 additions & 0 deletions .changeset/busy-hounds-take.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@lynx-js/web-mainthread-apis": patch
"@lynx-js/web-worker-runtime": patch
"@lynx-js/web-core": patch
---

feat: allow lynx code to get JS engine provided properties on globalThis

```
globalThis.Reflect; // this will be the Reflect Object
```

Note that `assigning to the globalThis` is still not allowed.
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,20 @@ export class MainThreadRuntime {
*/
__lynxGlobalBindingValues: Record<string, any> = {};

get globalThis() {
return this;
}
globalThis = new Proxy(this, {
get: (target, prop) => {
// @ts-expect-error
return target[prop] ?? globalThis[prop];
},
set: (target, prop, value) => {
// @ts-expect-error
target[prop] = value;
return true;
},
ownKeys(target) {
return Reflect.ownKeys(target).filter((key) => key !== 'globalThis');
},
});

SystemInfo: typeof systemInfo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function loadMainThread(
publicComponentEvent,
postExposure,
},
}).globalThis;
});
markTimingInternal('decode_end');
entry!(runtime);
jsContext.__start(); // start the jsContext after the runtime is created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function initializeMainThreadTest() {
},
postExposure: () => {},
},
});
}).globalThis;
Object.assign(globalThis, runtime);
Object.assign(globalThis, {
genFiberElementTree,
Expand Down
10 changes: 10 additions & 0 deletions packages/web-platform/web-tests/tests/react.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

const expectHasText = async (page: Page, text: string) => {
const hasText = (await page.getByText(text).count()) === 1;
await expect(hasText).toBe(true);

Check failure on line 38 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux-all-on-ui / check

[webkit] › tests/react.spec.ts:117:5 › reactlynx3 tests › basic › basic-setstate-in-constructor

2) [webkit] › tests/react.spec.ts:117:5 › reactlynx3 tests › basic › basic-setstate-in-constructor Error: expect(received).toBe(expected) // Object.is equality Expected: true Received: false 36 | const expectHasText = async (page: Page, text: string) => { 37 | const hasText = (await page.getByText(text).count()) === 1; > 38 | await expect(hasText).toBe(true); | ^ 39 | }; 40 | 41 | const expectNoText = async (page: Page, text: string) => { at expectHasText (/home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:38:25) at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:120:7

Check failure on line 38 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux-all-on-ui / check

[webkit] › tests/react.spec.ts:122:5 › reactlynx3 tests › basic › basic-setsate-with-cb

3) [webkit] › tests/react.spec.ts:122:5 › reactlynx3 tests › basic › basic-setsate-with-cb ─────── Error: expect(received).toBe(expected) // Object.is equality Expected: true Received: false 36 | const expectHasText = async (page: Page, text: string) => { 37 | const hasText = (await page.getByText(text).count()) === 1; > 38 | await expect(hasText).toBe(true); | ^ 39 | }; 40 | 41 | const expectNoText = async (page: Page, text: string) => { at expectHasText (/home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:38:25) at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:125:7
};

const expectNoText = async (page: Page, text: string) => {
Expand Down Expand Up @@ -387,6 +387,16 @@
await wait(100);
await expect(page.locator('#target')).toHaveCSS('color', 'rgb(0, 0, 0)');
});
test('basic-globalThis-property-bts', async ({ page }, { title }) => {
await goto(page, title);
await wait(100);
await expect(page.locator('#target')).toHaveCSS('color', 'rgb(0, 0, 0)');
});
test('basic-globalThis-property-mts', async ({ page }, { title }) => {
await goto(page, title);
await wait(100);
await expect(page.locator('#target')).toHaveCSS('color', 'rgb(0, 0, 0)');
});
});
test.describe('apis', () => {
test('api-custom-template-loader', async ({ page }, { title }) => {
Expand Down Expand Up @@ -933,7 +943,7 @@
globalThis.lynxView.sendGlobalEvent('event-test', ['change']);
});
await wait(100);
await expect(target).toHaveCSS(

Check failure on line 946 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux-all-on-ui / check

[webkit] › tests/react.spec.ts:937:5 › reactlynx3 tests › apis › api-sendGlobalEvent

4) [webkit] › tests/react.spec.ts:937:5 › reactlynx3 tests › apis › api-sendGlobalEvent ────────── Error: Timed out 5000ms waiting for expect(locator).toHaveCSS(expected) Locator: locator('#target') Expected string: "rgb(0, 128, 0)" Received string: "rgb(255, 192, 203)" Call log: - expect.toHaveCSS with timeout 5000ms - waiting for locator('#target') 9 × locator resolved to <x-view id="target" lynx-tag="view" lynx-unique-id="2"></x-view> - unexpected value "rgb(255, 192, 203)" 944 | }); 945 | await wait(100); > 946 | await expect(target).toHaveCSS( | ^ 947 | 'background-color', 948 | 'rgb(0, 128, 0)', 949 | ); // green; at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:946:28

Check failure on line 946 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux-all-on-ui / check

[chromium] › tests/react.spec.ts:937:5 › reactlynx3 tests › apis › api-sendGlobalEvent

9) [chromium] › tests/react.spec.ts:937:5 › reactlynx3 tests › apis › api-sendGlobalEvent ──────── Error: Timed out 5000ms waiting for expect(locator).toHaveCSS(expected) Locator: locator('#target') Expected string: "rgb(0, 128, 0)" Received string: "rgb(255, 192, 203)" Call log: - expect.toHaveCSS with timeout 5000ms - waiting for locator('#target') 9 × locator resolved to <x-view id="target" lynx-tag="view" lynx-unique-id="2"></x-view> - unexpected value "rgb(255, 192, 203)" 944 | }); 945 | await wait(100); > 946 | await expect(target).toHaveCSS( | ^ 947 | 'background-color', 948 | 'rgb(0, 128, 0)', 949 | ); // green; at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:946:28
'background-color',
'rgb(0, 128, 0)',
); // green;
Expand Down Expand Up @@ -1146,7 +1156,7 @@
await wait(100);
const target = page.locator('#target');
await target.click();
await expect(await target.getAttribute('style')).toContain('green');

Check failure on line 1159 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux-all-on-ui / check

[webkit] › tests/react.spec.ts:1154:5 › reactlynx3 tests › configs › config-mode-dev-with-all-in-one

5) [webkit] › tests/react.spec.ts:1154:5 › reactlynx3 tests › configs › config-mode-dev-with-all-in-one Error: expect(received).toContain(expected) // indexOf Expected substring: "green" Received string: "height: 100px; width: 100px; background: pink;" 1157 | const target = page.locator('#target'); 1158 | await target.click(); > 1159 | await expect(await target.getAttribute('style')).toContain('green'); | ^ 1160 | await target.click(); 1161 | await expect(await target.getAttribute('style')).toContain('pink'); 1162 | }); at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:1159:56

Check failure on line 1159 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:1154:5 › reactlynx3 tests › configs › config-mode-dev-with-all-in-one

2) [webkit] › tests/react.spec.ts:1154:5 › reactlynx3 tests › configs › config-mode-dev-with-all-in-one Error: expect(received).toContain(expected) // indexOf Expected substring: "green" Received string: "height: 100px; width: 100px; background: pink;" 1157 | const target = page.locator('#target'); 1158 | await target.click(); > 1159 | await expect(await target.getAttribute('style')).toContain('green'); | ^ 1160 | await target.click(); 1161 | await expect(await target.getAttribute('style')).toContain('pink'); 1162 | }); at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:1159:56
await target.click();
await expect(await target.getAttribute('style')).toContain('pink');
});
Expand Down Expand Up @@ -1395,7 +1405,7 @@
await wait(500);
const count = (await page.getByText('the count is:1').count())
+ (await await page.getByText('the count is:2').count());
expect(count).toBe(1);

Check failure on line 1408 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux-all-on-ui / check

[webkit] › tests/react.spec.ts:1401:7 › reactlynx3 tests › elements › text › basic-element-text-set-native-props-text

6) [webkit] › tests/react.spec.ts:1401:7 › reactlynx3 tests › elements › text › basic-element-text-set-native-props-text Error: expect(received).toBe(expected) // Object.is equality Expected: 1 Received: 0 1406 | const count = (await page.getByText('the count is:1').count()) 1407 | + (await await page.getByText('the count is:2').count()); > 1408 | expect(count).toBe(1); | ^ 1409 | }, 1410 | ); 1411 | at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:1408:25
},
);

Expand Down Expand Up @@ -2086,7 +2096,7 @@
await page.locator('.focus').click({ force: true });
await wait(100);
const result = await page.locator('.result').first().innerText();
expect(result).toBe('bindfocus');

Check failure on line 2099 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:2091:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-focus

3) [webkit] › tests/react.spec.ts:2091:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-focus Error: expect(received).toBe(expected) // Object.is equality Expected: "bindfocus" Received: "" 2097 | await wait(100); 2098 | const result = await page.locator('.result').first().innerText(); > 2099 | expect(result).toBe('bindfocus'); | ^ 2100 | }, 2101 | ); 2102 | // input/focus test-case end at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:2099:26

Check failure on line 2099 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:2091:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-focus

3) [webkit] › tests/react.spec.ts:2091:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-focus Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: "bindfocus" Received: "" 2097 | await wait(100); 2098 | const result = await page.locator('.result').first().innerText(); > 2099 | expect(result).toBe('bindfocus'); | ^ 2100 | }, 2101 | ); 2102 | // input/focus test-case end at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:2099:26

Check failure on line 2099 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:2091:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-focus

3) [webkit] › tests/react.spec.ts:2091:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-focus Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: "bindfocus" Received: "" 2097 | await wait(100); 2098 | const result = await page.locator('.result').first().innerText(); > 2099 | expect(result).toBe('bindfocus'); | ^ 2100 | }, 2101 | ); 2102 | // input/focus test-case end at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:2099:26

Check failure on line 2099 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:2091:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-focus

3) [webkit] › tests/react.spec.ts:2091:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-focus Retry #3 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: "bindfocus" Received: "" 2097 | await wait(100); 2098 | const result = await page.locator('.result').first().innerText(); > 2099 | expect(result).toBe('bindfocus'); | ^ 2100 | }, 2101 | ); 2102 | // input/focus test-case end at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:2099:26
},
);
// input/focus test-case end
Expand All @@ -2097,7 +2107,7 @@
await page.locator('input').click({ force: true });
await wait(100);
const result = await page.locator('.result').first().innerText();
expect(result).toBe('bindfocus');

Check failure on line 2110 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux-all-on-ui / check

[webkit] › tests/react.spec.ts:2105:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindfocus

7) [webkit] › tests/react.spec.ts:2105:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindfocus Error: expect(received).toBe(expected) // Object.is equality Expected: "bindfocus" Received: "" 2108 | await wait(100); 2109 | const result = await page.locator('.result').first().innerText(); > 2110 | expect(result).toBe('bindfocus'); | ^ 2111 | }); 2112 | // input/bindfocus test-case end 2113 | at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:2110:24

Check failure on line 2110 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:2105:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindfocus

4) [webkit] › tests/react.spec.ts:2105:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindfocus Error: expect(received).toBe(expected) // Object.is equality Expected: "bindfocus" Received: "" 2108 | await wait(100); 2109 | const result = await page.locator('.result').first().innerText(); > 2110 | expect(result).toBe('bindfocus'); | ^ 2111 | }); 2112 | // input/bindfocus test-case end 2113 | at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:2110:24
});
// input/bindfocus test-case end

Expand All @@ -2107,7 +2117,7 @@
await page.locator('input').press('Enter');
await wait(100);
const result = await page.locator('.result').first().innerText();
expect(result).toBe('bindconfirm');

Check failure on line 2120 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux-all-on-ui / check

[webkit] › tests/react.spec.ts:2115:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindconfirm

8) [webkit] › tests/react.spec.ts:2115:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindconfirm Error: expect(received).toBe(expected) // Object.is equality Expected: "bindconfirm" Received: "" 2118 | await wait(100); 2119 | const result = await page.locator('.result').first().innerText(); > 2120 | expect(result).toBe('bindconfirm'); | ^ 2121 | }); 2122 | // input/bindconfirm test-case end 2123 | at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:2120:24

Check failure on line 2120 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:2115:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindconfirm

5) [webkit] › tests/react.spec.ts:2115:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindconfirm Error: expect(received).toBe(expected) // Object.is equality Expected: "bindconfirm" Received: "" 2118 | await wait(100); 2119 | const result = await page.locator('.result').first().innerText(); > 2120 | expect(result).toBe('bindconfirm'); | ^ 2121 | }); 2122 | // input/bindconfirm test-case end 2123 | at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:2120:24

Check failure on line 2120 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:2115:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindconfirm

5) [webkit] › tests/react.spec.ts:2115:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindconfirm Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: "bindconfirm" Received: "" 2118 | await wait(100); 2119 | const result = await page.locator('.result').first().innerText(); > 2120 | expect(result).toBe('bindconfirm'); | ^ 2121 | }); 2122 | // input/bindconfirm test-case end 2123 | at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:2120:24
});
// input/bindconfirm test-case end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
import { root } from '@lynx-js/react';

function App() {
return (
<view
id='target'
style={{
height: '100px',
width: '100px',
background: globalThis.Object ? 'green' : 'pink',
}}
/>
);
}

root.render(<App></App>);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2023 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
import { useState, root, useEffect } from '@lynx-js/react';
function App() {
const [color, setColor] = useState('pink');
useEffect(() => {
if (globalThis.Object) {
setColor('green');
}
}, []);
return (
<view
id='target'
style={{
height: '100px',
width: '100px',
background: color,
}}
/>
);
}
root.render(<App />);
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,22 @@ export async function createNativeApp(config: {
return {
init: (lynxCoreInject) => {
lynxCoreInject.tt.lynxCoreInject = lynxCoreInject;
lynxCoreInject.tt.globalThis ??= lynxCoreInject;
lynxCoreInject.tt.globalThis ??= new Proxy(lynxCoreInject, {
get(target, prop) {
// @ts-expect-error
return target[prop] ?? globalThis[prop];
},
set(target, prop, value) {
// @ts-expect-error
target[prop] = value;
return true;
},
ownKeys(target) {
return Reflect.ownKeys(target).filter((key) =>
key !== 'globalThis'
);
},
});
Object.assign(lynxCoreInject.tt, {
SystemInfo: { ...systemInfo, ...browserConfig },
});
Expand Down
Loading