forked from scratchfoundation/scratch-vm
-
-
Notifications
You must be signed in to change notification settings - Fork 95
Super scary extension development improvments. #259
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
Open
yuri-kiss
wants to merge
21
commits into
TurboWarp:develop
Choose a base branch
from
TwForks:refreshBlocks
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d935e58
Add Scratch.extensions.worker
yuri-kiss 87f1071
unsandboxed extensions: ext.refresh
yuri-kiss 91a2ca4
Add a simple message handler for sandboxed and worker extensions to use.
yuri-kiss 8bcf53f
add ext.loadBuiltIn
yuri-kiss 69e610d
fix grammatical errors
yuri-kiss 49b5ea0
add ext.loadBuiltIn and ext.refresh
yuri-kiss 0bbbff6
fix eslint
yuri-kiss 6e77618
add more casting stuff
yuri-kiss a7eb279
add some more VM exports for extensions
yuri-kiss 75eab4f
move message callback to its own function
yuri-kiss f6f55d0
Super insanely scary require export :)
yuri-kiss bd163ae
add shared extension utils to the exports (for obvious reasons)
yuri-kiss 10f96c7
refine this comment
yuri-kiss 076c08a
clarify this change
yuri-kiss 4059132
clarify why I made the change to check for global.addEventListener
yuri-kiss da10dc8
fix tests
yuri-kiss 71d3113
fix critical dependency issue and simplify the scarey require export
yuri-kiss caed383
prevent prototype pollution
yuri-kiss 3144ccc
clarify why I am exporting the Scratch stuff
yuri-kiss 2d9790e
remove this false comment
yuri-kiss a48d99c
fix goofy bug
yuri-kiss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @fileoverview Responsible for giving unsandboxed extensions their extra tools. | ||
* This is exposed on the VM for ease of use and to prevent duplicate code. | ||
*/ | ||
|
||
class ExtensionTools { | ||
// Internal functions. | ||
static xmlEscape = require('../util/xml-escape'); | ||
static uid = require('../util/uid'); | ||
static fetchStatic = require('../util/tw-static-fetch'); | ||
static fetchWithTimeout = require('../util/fetch-with-timeout').fetchWithTimeout; | ||
static setFetchWithTimeoutFetchFn = require('../util/fetch-with-timeout').setFetch; | ||
static isNotActuallyZero = require('../util/is-not-actually-zero'); | ||
static getMonitorID = require('../util/get-monitor-id'); | ||
static maybeFormatMessage = require('../util/maybe-format-message'); | ||
static newBlockIds = require('../util/new-block-ids'); | ||
static hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key); | ||
// External classes / functions. | ||
static nanolog = require('@turbowarp/nanolog'); | ||
static log = require('../util/log'); | ||
static buffers = require('buffer'); | ||
static TextEncoder = require('text-encoding').TextEncoder; | ||
static TextDecoder = require('text-encoding').TextDecoder; | ||
static twjson = require('@turbowarp/json'); | ||
// Internal classes. | ||
static math = require('../util/math-util'); | ||
static assets = require('../util/tw-asset-util'); | ||
static base64 = require('../util/base64-util'); | ||
static strings = require('../util/string-util'); | ||
static variables = require('../util/variable-util'); | ||
static asyncLimiter = require('../util/async-limiter'); | ||
static clone = require('../util/clone'); | ||
static sanitizer = require('../util/value-sanitizer'); | ||
static jsonrpc = require('../util/jsonrpc'); | ||
static color = require('../util/color'); | ||
static rateLimiter = require('../util/rateLimiter'); | ||
static scratchLinkWebSocket = require('../util/scratch-link-websocket'); | ||
static taskQueue = require('../util/task-queue'); | ||
static timer = require('../util/timer'); | ||
static sharedDispatch = require('../dispatch/shared-dispatch'); | ||
// Instanced dispatchers. | ||
static centralDispatch = require('../dispatch/central-dispatch'); | ||
static workerDispatch = require('../dispatch/worker-dispatch'); | ||
} | ||
|
||
module.exports = ExtensionTools; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Used internally by compare() | ||
* @param {*} val A value that evaluates to 0 in JS string-to-number conversation such as empty string, 0, or tab. | ||
* @returns {boolean} True if the value should not be treated as the number zero. | ||
*/ | ||
const isNotActuallyZero = val => { | ||
if (typeof val !== 'string') return false; | ||
for (let i = 0; i < val.length; i++) { | ||
const code = val.charCodeAt(i); | ||
// '0'.charCodeAt(0) === 48 | ||
// '\t'.charCodeAt(0) === 9 | ||
// We include tab for compatibility with scratch-www's broken trim() polyfill. | ||
// https://github.com/TurboWarp/scratch-vm/issues/115 | ||
// https://scratch.mit.edu/projects/788261699/ | ||
if (code === 48 || code === 9) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
|
||
module.exports = isNotActuallyZero; |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll just say right away that extending worker extensions with more powers is probably just not going to happen; if anything these are getting removed entirely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know they are going to get removed but they exist right now, so I don't see why it cant be added now.