diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 6fc794268f..17cd755dcf 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -22,6 +22,7 @@ const xmlEscape = require('../util/xml-escape'); const ScratchLinkWebSocket = require('../util/scratch-link-websocket'); const FontManager = require('./tw-font-manager'); const fetchWithTimeout = require('../util/fetch-with-timeout'); +const platform = require('./tw-platform.js'); // Virtual I/O devices. const Clock = require('../io/clock'); @@ -439,6 +440,11 @@ class Runtime extends EventEmitter { */ this.origin = null; + /** + * Metadata about the platform this VM is part of. + */ + this.platform = Object.assign({}, platform); + this._initScratchLink(); this.resetRunId(); diff --git a/src/engine/tw-platform.js b/src/engine/tw-platform.js new file mode 100644 index 0000000000..ee6a2e2d62 --- /dev/null +++ b/src/engine/tw-platform.js @@ -0,0 +1,7 @@ +// Forks should change this. +// This can be accessed externally on `vm.runtime.platform` + +module.exports = { + name: 'TurboWarp', + url: 'https://turbowarp.org/' +}; diff --git a/src/serialization/sb3.js b/src/serialization/sb3.js index d3c0dd0d3e..99397b2759 100644 --- a/src/serialization/sb3.js +++ b/src/serialization/sb3.js @@ -794,11 +794,8 @@ const serialize = function (runtime, targetId, {allowOptimization = true} = {}) // TW: Never include full user agent to slightly improve user privacy // if (typeof navigator !== 'undefined') meta.agent = navigator.userAgent; - // TW: Attach platform information (should be changed for forks of TurboWarp) - const platform = Object.create(null); - platform.name = 'TurboWarp'; - platform.url = 'https://turbowarp.org/'; - meta.platform = platform; + // TW: Attach copy of platform information + meta.platform = Object.assign({}, runtime.platform); // Assemble payload and return obj.meta = meta; diff --git a/test/integration/tw_platform.js b/test/integration/tw_platform.js new file mode 100644 index 0000000000..84b3aaf352 --- /dev/null +++ b/test/integration/tw_platform.js @@ -0,0 +1,26 @@ +const {test} = require('tap'); +const VM = require('../../src/virtual-machine'); +const platform = require('../../src/engine/tw-platform'); + +test('the internal object', t => { + // the idea with this test is to make it harder for forks to screw up modifying the file + t.type(platform.name, 'string'); + t.type(platform.url, 'string'); + t.end(); +}); + +test('vm property', t => { + const vm = new VM(); + t.same(vm.runtime.platform, platform, 'copy of tw-platform.js'); + t.not(vm.runtime.platform, platform, 'not the same object as tw-platform.js'); + t.end(); +}); + +test('sanitize', t => { + const vm = new VM(); + vm.runtime.platform.name += ' - test'; + const json = JSON.parse(vm.toJSON()); + t.same(json.meta.platform, vm.runtime.platform, 'copy of runtime.platform'); + t.not(json.meta.platform, vm.runtime.platform, 'not the same object as runtime.platform'); + t.end(); +});