From 2d2b691b6f0e5c9f082c3f85639185c4fd987784 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 6 Dec 2017 11:21:00 -0500 Subject: [PATCH] Return a default falsey value for unknown params based on param type --- src/blocks/scratch3_procedures.js | 17 ++++++++++++++--- test/unit/engine_thread.js | 4 +++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/blocks/scratch3_procedures.js b/src/blocks/scratch3_procedures.js index 645e582ed..3ba743d8b 100644 --- a/src/blocks/scratch3_procedures.js +++ b/src/blocks/scratch3_procedures.js @@ -15,8 +15,8 @@ class Scratch3ProcedureBlocks { return { procedures_definition: this.definition, procedures_call: this.call, - argument_reporter_string_number: this.param, - argument_reporter_boolean: this.param + argument_reporter_string_number: this.argumentReporterStringNumber, + argument_reporter_boolean: this.argumentReporterBoolean }; } @@ -47,8 +47,19 @@ class Scratch3ProcedureBlocks { } } - param (args, util) { + argumentReporterStringNumber (args, util) { const value = util.getParam(args.VALUE); + if (value === null) { + return ''; + } + return value; + } + + argumentReporterBoolean (args, util) { + const value = util.getParam(args.VALUE); + if (value === null) { + return false; + } return value; } } diff --git a/test/unit/engine_thread.js b/test/unit/engine_thread.js index 533f72523..15fab7c02 100644 --- a/test/unit/engine_thread.js +++ b/test/unit/engine_thread.js @@ -110,7 +110,9 @@ test('PushGetParam', t => { th.pushParam('testParam', 'testValue'); t.strictEquals(th.peekStackFrame().params.testParam, 'testValue'); t.strictEquals(th.getParam('testParam'), 'testValue'); - + // Params outside of define stack always evaluate to null + t.strictEquals(th.getParam('nonExistentParam'), null); + t.end(); });