mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
Merge pull request #446 from magmaboat/hasownproperty
Perform hasOwnProperty validation
This commit is contained in:
commit
a56db95aba
6 changed files with 16 additions and 2 deletions
|
@ -193,6 +193,7 @@ Scratch3SoundBlocks.prototype.changeEffect = function (args, util) {
|
||||||
Scratch3SoundBlocks.prototype.clearEffects = function (args, util) {
|
Scratch3SoundBlocks.prototype.clearEffects = function (args, util) {
|
||||||
var soundState = this._getSoundState(util.target);
|
var soundState = this._getSoundState(util.target);
|
||||||
for (var effect in soundState.effects) {
|
for (var effect in soundState.effects) {
|
||||||
|
if (!soundState.effects.hasOwnProperty(effect)) continue;
|
||||||
soundState.effects[effect] = 0;
|
soundState.effects[effect] = 0;
|
||||||
}
|
}
|
||||||
if (util.target.audioPlayer === null) return;
|
if (util.target.audioPlayer === null) return;
|
||||||
|
|
|
@ -24,6 +24,7 @@ var domToBlocks = function (blocksDOM) {
|
||||||
// Flatten blocks object into a list.
|
// Flatten blocks object into a list.
|
||||||
var blocksList = [];
|
var blocksList = [];
|
||||||
for (var b in blocks) {
|
for (var b in blocks) {
|
||||||
|
if (!blocks.hasOwnProperty(b)) continue;
|
||||||
blocksList.push(blocks[b]);
|
blocksList.push(blocks[b]);
|
||||||
}
|
}
|
||||||
return blocksList;
|
return blocksList;
|
||||||
|
|
|
@ -149,6 +149,7 @@ Blocks.prototype.getTopLevelScript = function (id) {
|
||||||
*/
|
*/
|
||||||
Blocks.prototype.getProcedureDefinition = function (name) {
|
Blocks.prototype.getProcedureDefinition = function (name) {
|
||||||
for (var id in this._blocks) {
|
for (var id in this._blocks) {
|
||||||
|
if (!this._blocks.hasOwnProperty(id)) continue;
|
||||||
var block = this._blocks[id];
|
var block = this._blocks[id];
|
||||||
if ((block.opcode === 'procedures_defnoreturn' ||
|
if ((block.opcode === 'procedures_defnoreturn' ||
|
||||||
block.opcode === 'procedures_defreturn') &&
|
block.opcode === 'procedures_defreturn') &&
|
||||||
|
@ -166,6 +167,7 @@ Blocks.prototype.getProcedureDefinition = function (name) {
|
||||||
*/
|
*/
|
||||||
Blocks.prototype.getProcedureParamNames = function (name) {
|
Blocks.prototype.getProcedureParamNames = function (name) {
|
||||||
for (var id in this._blocks) {
|
for (var id in this._blocks) {
|
||||||
|
if (!this._blocks.hasOwnProperty(id)) continue;
|
||||||
var block = this._blocks[id];
|
var block = this._blocks[id];
|
||||||
if ((block.opcode === 'procedures_defnoreturn' ||
|
if ((block.opcode === 'procedures_defnoreturn' ||
|
||||||
block.opcode === 'procedures_defreturn') &&
|
block.opcode === 'procedures_defreturn') &&
|
||||||
|
@ -415,6 +417,7 @@ Blocks.prototype.blockToXML = function (blockId) {
|
||||||
}
|
}
|
||||||
// Add any inputs on this block.
|
// Add any inputs on this block.
|
||||||
for (var input in block.inputs) {
|
for (var input in block.inputs) {
|
||||||
|
if (!block.inputs.hasOwnProperty(input)) continue;
|
||||||
var blockInput = block.inputs[input];
|
var blockInput = block.inputs[input];
|
||||||
// Only encode a value tag if the value input is occupied.
|
// Only encode a value tag if the value input is occupied.
|
||||||
if (blockInput.block || blockInput.shadow) {
|
if (blockInput.block || blockInput.shadow) {
|
||||||
|
@ -431,6 +434,7 @@ Blocks.prototype.blockToXML = function (blockId) {
|
||||||
}
|
}
|
||||||
// Add any fields on this block.
|
// Add any fields on this block.
|
||||||
for (var field in block.fields) {
|
for (var field in block.fields) {
|
||||||
|
if (!block.fields.hasOwnProperty(field)) continue;
|
||||||
var blockField = block.fields[field];
|
var blockField = block.fields[field];
|
||||||
var value = blockField.value;
|
var value = blockField.value;
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
|
|
|
@ -110,6 +110,7 @@ var execute = function (sequencer, thread) {
|
||||||
Object.keys(inputs).length === 0) {
|
Object.keys(inputs).length === 0) {
|
||||||
// One field and no inputs - treat as arg.
|
// One field and no inputs - treat as arg.
|
||||||
for (var fieldKey in fields) { // One iteration.
|
for (var fieldKey in fields) { // One iteration.
|
||||||
|
if (!fields.hasOwnProperty(fieldKey)) continue;
|
||||||
handleReport(fields[fieldKey].value);
|
handleReport(fields[fieldKey].value);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -126,11 +127,13 @@ var execute = function (sequencer, thread) {
|
||||||
|
|
||||||
// Add all fields on this block to the argValues.
|
// Add all fields on this block to the argValues.
|
||||||
for (var fieldName in fields) {
|
for (var fieldName in fields) {
|
||||||
|
if (!fields.hasOwnProperty(fieldName)) continue;
|
||||||
argValues[fieldName] = fields[fieldName].value;
|
argValues[fieldName] = fields[fieldName].value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursively evaluate input blocks.
|
// Recursively evaluate input blocks.
|
||||||
for (var inputName in inputs) {
|
for (var inputName in inputs) {
|
||||||
|
if (!inputs.hasOwnProperty(inputName)) continue;
|
||||||
var input = inputs[inputName];
|
var input = inputs[inputName];
|
||||||
var inputBlockId = input.block;
|
var inputBlockId = input.block;
|
||||||
// Is there no value for this input waiting in the stack frame?
|
// Is there no value for this input waiting in the stack frame?
|
||||||
|
|
|
@ -441,6 +441,7 @@ Runtime.prototype.startHats = function (requestedHatOpcode,
|
||||||
var newThreads = [];
|
var newThreads = [];
|
||||||
|
|
||||||
for (var opts in optMatchFields) {
|
for (var opts in optMatchFields) {
|
||||||
|
if (!optMatchFields.hasOwnProperty(opts)) continue;
|
||||||
optMatchFields[opts] = optMatchFields[opts].toUpperCase();
|
optMatchFields[opts] = optMatchFields[opts].toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,6 +464,7 @@ Runtime.prototype.startHats = function (requestedHatOpcode,
|
||||||
if (Object.keys(hatFields).length === 0) {
|
if (Object.keys(hatFields).length === 0) {
|
||||||
var hatInputs = target.blocks.getInputs(topBlockId);
|
var hatInputs = target.blocks.getInputs(topBlockId);
|
||||||
for (var input in hatInputs) {
|
for (var input in hatInputs) {
|
||||||
|
if (!hatInputs.hasOwnProperty(input)) continue;
|
||||||
var id = hatInputs[input].block;
|
var id = hatInputs[input].block;
|
||||||
var fields = target.blocks.getFields(id);
|
var fields = target.blocks.getFields(id);
|
||||||
hatFields = Object.assign(fields, hatFields);
|
hatFields = Object.assign(fields, hatFields);
|
||||||
|
@ -592,6 +594,7 @@ Runtime.prototype.stopAll = function () {
|
||||||
Runtime.prototype._step = function () {
|
Runtime.prototype._step = function () {
|
||||||
// Find all edge-activated hats, and add them to threads to be evaluated.
|
// Find all edge-activated hats, and add them to threads to be evaluated.
|
||||||
for (var hatType in this._hats) {
|
for (var hatType in this._hats) {
|
||||||
|
if (!this._hats.hasOwnProperty(hatType)) continue;
|
||||||
var hat = this._hats[hatType];
|
var hat = this._hats[hatType];
|
||||||
if (hat.edgeActivated) {
|
if (hat.edgeActivated) {
|
||||||
this.startHats(hatType);
|
this.startHats(hatType);
|
||||||
|
|
|
@ -315,6 +315,7 @@ RenderedTarget.prototype.setEffect = function (effectName, value) {
|
||||||
*/
|
*/
|
||||||
RenderedTarget.prototype.clearEffects = function () {
|
RenderedTarget.prototype.clearEffects = function () {
|
||||||
for (var effectName in this.effects) {
|
for (var effectName in this.effects) {
|
||||||
|
if (!this.effects.hasOwnProperty(effectName)) continue;
|
||||||
this.effects[effectName] = 0;
|
this.effects[effectName] = 0;
|
||||||
}
|
}
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
|
@ -434,8 +435,9 @@ RenderedTarget.prototype.updateAllDrawableProperties = function () {
|
||||||
costume.rotationCenterY / costume.bitmapResolution
|
costume.rotationCenterY / costume.bitmapResolution
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
for (var effectID in this.effects) {
|
for (var effectName in this.effects) {
|
||||||
props[effectID] = this.effects[effectID];
|
if (!this.effects.hasOwnProperty(effectName)) continue;
|
||||||
|
props[effectName] = this.effects[effectName];
|
||||||
}
|
}
|
||||||
this.renderer.updateDrawableProperties(this.drawableID, props);
|
this.renderer.updateDrawableProperties(this.drawableID, props);
|
||||||
if (this.visible) {
|
if (this.visible) {
|
||||||
|
|
Loading…
Reference in a new issue