WIP: Add vm polyfill for browser#40
Open
a-mountain wants to merge 1 commit into
Open
Conversation
tshemsedinov
reviewed
Dec 8, 2020
| @@ -0,0 +1,193 @@ | |||
| # VM BROWSER | |||
Member
There was a problem hiding this comment.
Please rename to doc/vm-browser.md and format with prettier.
Comment on lines
+54
to
+63
| .map((error) => ({ | ||
| name: error.name, | ||
| newError: class ErrorWithFilename extends error { | ||
| constructor(message, filename, lineNumber) { | ||
| super(message, filename, lineNumber); | ||
| this.filename = errorFilename; | ||
| } | ||
| }, | ||
| })) | ||
| .forEach((v) => (contentWindow[v.name] = v.newError)); |
Comment on lines
+13
to
+16
| const throwEvalError = () => { | ||
| const msg = 'Code generation from strings disallowed for this context'; | ||
| throw new EvalError(msg); | ||
| }; |
Member
There was a problem hiding this comment.
Suggested change
| const throwEvalError = () => { | |
| const msg = 'Code generation from strings disallowed for this context'; | |
| throw new EvalError(msg); | |
| }; | |
| const ERR_EVAL = 'Code generation from strings disallowed for this context'; |
Member
There was a problem hiding this comment.
Use throw new Error(ERR_EVAL); from all other places
| constructor(code, options = {}) { | ||
| this.code = code; | ||
| if (isFilename(options)) { | ||
| options = makeOptionsFromFilename(options); |
tshemsedinov
reviewed
Mar 7, 2023
tshemsedinov
left a comment
Member
There was a problem hiding this comment.
Also please rebase on master
| element.style.display = 'none'; | ||
| element.id = id; | ||
| element.name = name; | ||
| element.className = IFRAME_CLASS_DEFAULT; |
Comment on lines
+42
to
+49
| const wrappedErrors = errors.map((error) => ({ | ||
| name: error.name, | ||
| newError: class ErrorWithFilename extends error { | ||
| constructor(message, filename, lineNumber) { | ||
| super(message, filename, lineNumber); | ||
| this.filename = errorFilename; | ||
| } | ||
| }, |
Member
There was a problem hiding this comment.
Suggested change
| const wrappedErrors = errors.map((error) => ({ | |
| name: error.name, | |
| newError: class ErrorWithFilename extends error { | |
| constructor(message, filename, lineNumber) { | |
| super(message, filename, lineNumber); | |
| this.filename = errorFilename; | |
| } | |
| }, | |
| const wrappedErrors = errors.map((ErrorClass) => ({ | |
| name: ErrorClass.name, | |
| newError: class ErrorWithFilename extends ErrorClass { | |
| constructor(message, filename, lineNumber) { | |
| super(message, filename, lineNumber); | |
| this.filename = errorFilename; | |
| } | |
| }, |
| } | ||
| }, | ||
| })); | ||
| for (const wrappedError of wrappedErrors) { |
Member
There was a problem hiding this comment.
Avoid double loops over error classes collection
| } | ||
| }, | ||
| })); | ||
| for (const wrappedError of wrappedErrors) { |
Member
There was a problem hiding this comment.
Suggested change
| for (const wrappedError of wrappedErrors) { | |
| for (const ErrorClass of wrappedErrors) { |
| }; | ||
|
|
||
| const createIframe = (document, context, options) => { | ||
| const id = `iframe-vm:${Date.now()}`; |
Comment on lines
+85
to
+104
| return { | ||
| id, | ||
| deleteFromDocument() { | ||
| if (isAttachedToDocument()) { | ||
| document.body.removeChild(element); | ||
| } | ||
| }, | ||
| updateContext() { | ||
| if (isAttachedToDocument()) { | ||
| for (const [key, value] of Object.entries(contentWindow)) { | ||
| if (isContextKey(key) || canAddNewKey(key)) { | ||
| context[key] = value; | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| runScript(script) { | ||
| return runScript(script); | ||
| }, | ||
| }; |
Comment on lines
+123
to
+124
| return { | ||
| updateContext() { |
Comment on lines
+154
to
+157
| } catch (e) { | ||
| deleteIframe(iframe); | ||
| throw e; | ||
| } |
Member
There was a problem hiding this comment.
Suggested change
| } catch (e) { | |
| deleteIframe(iframe); | |
| throw e; | |
| } | |
| } catch (error) { | |
| deleteIframe(iframe); | |
| throw error; | |
| } |
a-mountain
force-pushed
the
add-polyfill-vm
branch
2 times, most recently
from
March 8, 2023 14:18
aa135e3 to
fd357e8
Compare
a-mountain
force-pushed
the
add-polyfill-vm
branch
from
April 29, 2023 15:13
fd357e8 to
fee449b
Compare
a-mountain
force-pushed
the
add-polyfill-vm
branch
from
April 29, 2023 15:33
fee449b to
f4109ae
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allows run script in iframe with your context
Add tests
npm run t)npm run fmt)