Skip to content

Commit

Permalink
Added additional type check to classes. Fixed an issue with wrong typ…
Browse files Browse the repository at this point in the history
…e assumption in equals function.
HoLyVieR committed May 30, 2019
1 parent 18804b7 commit da8e7f3
Showing 9 changed files with 56 additions and 8 deletions.
10 changes: 9 additions & 1 deletion classes/concatenation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/// class Concatenation

function Concatenation(value1, value2) {
if (value1 === null) {
throw new Error("value1 can't be null");
}

if (value2 === null) {
throw new Error("value1 can't be null");
}

this.values = [];
this.values.push(value1);
this.values.push(value2);
@@ -22,4 +30,4 @@ Concatenation.prototype.equals = function (val) {
return val.values[0].equals(this.values[0]) && val.values[1].equals(this.values[1]);
}

module.exports = Concatenation;
module.exports = Concatenation;
2 changes: 1 addition & 1 deletion classes/constant.js
Original file line number Diff line number Diff line change
@@ -16,4 +16,4 @@ Constant.prototype.equals = function (val) {
return this.value === val.value;
}

module.exports = Constant;
module.exports = Constant;
12 changes: 12 additions & 0 deletions classes/function-argument.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/// class FunctionArgument

function FunctionArgument(fnct, variableName, index) {
if (!fnct) {
throw new Error("Type of fnct must be string or object.");
}

if (typeof variableName !== "string") {
throw new Error("Type of variableName must be string.");
}

if (typeof index !== "number") {
throw new Error("Type of index must be number.");
}

this.name = variableName;
this.fnct = fnct;
this.index = index;
2 changes: 1 addition & 1 deletion classes/function-invocation.js
Original file line number Diff line number Diff line change
@@ -29,4 +29,4 @@ FunctionInvocation.prototype.equals = function (val) {
return good;
}

module.exports = FunctionInvocation;
module.exports = FunctionInvocation;
10 changes: 9 additions & 1 deletion classes/global-function-call.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/// class GlobalFunctionCall

function GlobalFunctionCall(name, args) {
if (typeof name !== "string") {
throw new Error("Type of name must be string.");
}

if (typeof args !== "object" || typeof args.length !== "number") {
throw new Error("Type of args must be array.");
}

this.name = name;
this.arguments = args;
}
@@ -41,4 +49,4 @@ GlobalFunctionCall.prototype.equals = function (val) {
return good;
}

module.exports = GlobalFunctionCall;
module.exports = GlobalFunctionCall;
12 changes: 10 additions & 2 deletions classes/local-function-call.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/// class LocalFunctionCall

function LocalFunctionCall(reference, args) {
if (reference == null) {
throw new Exception("Reference is null.");
}

if (typeof args !== "object" || typeof args.length !== "number") {
throw new Error("Type of args must be array.");
}

this.arguments = args;
this.reference = reference;
}
@@ -19,7 +27,7 @@ LocalFunctionCall.prototype.equals = function (val) {
return false;
}

if (!this.reference.equals(val.reference)) {
if (this.reference !== val.reference) {
return false;
}

@@ -38,4 +46,4 @@ LocalFunctionCall.prototype.equals = function (val) {
return good;
}

module.exports = LocalFunctionCall;
module.exports = LocalFunctionCall;
6 changes: 5 additions & 1 deletion classes/member-expression.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/// class MemberExpression

function MemberExpression(parts) {
if (typeof parts !== "object" || typeof parts.length !== "number") {
throw new Error("Type of parts must be array.");
}

this.parts = parts;
}

@@ -33,4 +37,4 @@ MemberExpression.prototype.equals = function (val) {
return good;
}

module.exports = MemberExpression;
module.exports = MemberExpression;
4 changes: 4 additions & 0 deletions classes/object-function-call.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@
var MemberExpression = require("./member-expression");

function ObjectFunctionCall(members, args) {
if (typeof args !== "object" || typeof args.length !== "number") {
throw new Error("Type of args must be array.");
}

this.members = new MemberExpression(members);
this.arguments = args;
}
6 changes: 5 additions & 1 deletion classes/reference.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@
var CONST_SEPARATOR_ID = "&&&";

function Reference(name) {
if (typeof name !== "string") {
throw new Error("Type of name must be string.");
}

this.name = name;
}

@@ -18,4 +22,4 @@ Reference.prototype.equals = function (val) {
return this.name === val.name;
}

module.exports = Reference;
module.exports = Reference;

0 comments on commit da8e7f3

Please sign in to comment.