Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(driver): move evaluateOnNewDocument to executionContext #12381

Merged
merged 10 commits into from
Apr 21, 2021

Conversation

patrickhulce
Copy link
Collaborator

Summary
Split out from #12366 and follow up to #12365, this moves the script evaluation on new document logic to executionContext, and aligns its call signature with our new preferred evaluate syntax that can be typechecked. This also completes the colocation of all the cached native definition and usage (except ElementMatches), so no need to reference window.__nativePromise ever again :D

Related Issues/PRs
ref #11313 #12366

@patrickhulce patrickhulce requested a review from a team as a code owner April 20, 2021 14:41
@patrickhulce patrickhulce requested review from connorjclark and removed request for a team April 20, 2021 14:41
@google-cla google-cla bot added the cla: yes label Apr 20, 2021
__nativePromise: PromiseConstructor;
__nativeURL: URL;
__nativePerformance: Performance;
__nativeURL: typeof URL;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was typed incorrectly, but we never use it :)

* Evaluate a function on every new frame from now on.
* @template {any[]} T
* @param {((...args: T) => void)} mainFn The main function to call.
* @param {{args: T, deps?: Array<Function|string>}} options `args` should
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yayyy

@@ -83,11 +85,10 @@ class ExecutionContext {
// 3. Ensure that errors captured in the Promise are converted into plain-old JS Objects
// so that they can be serialized properly b/c JSON.stringify(new Error('foo')) === '{}'
expression: `(function wrapInNativePromise() {
const __nativePromise = globalThis.__nativePromise || Promise;
const URL = globalThis.__nativeURL || globalThis.URL;
${ExecutionContext._cachedNativesPreamble};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice!

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice!

indeed!

lighthouse-core/gather/driver/execution-context.js Outdated Show resolved Hide resolved
lighthouse-core/gather/driver/execution-context.js Outdated Show resolved Hide resolved
lighthouse-core/gather/driver/execution-context.js Outdated Show resolved Hide resolved
Co-authored-by: Brendan Kenny <bckenny@gmail.com>
@patrickhulce patrickhulce merged commit 5d7fc8e into master Apr 21, 2021
@patrickhulce patrickhulce deleted the fr_refactor_cache_natives branch April 21, 2021 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants