Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
110 additions
and
21,083 deletions.
There are no files selected for viewing
This file contains 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 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,30 @@ | ||
///<reference path='node.d.ts' /> | ||
|
||
var ijjp = require("./ifacejsonjsproxy") | ||
var typeCheck = ijjp.typeCheck; | ||
var schemas = ijjp.extractSchemas(module); | ||
|
||
var JSVenv = require("JSV").JSV.createEnvironment(); | ||
|
||
enum Color { | ||
BLACK, | ||
RED | ||
} | ||
|
||
interface PhysicalObject { color : Color; intact : bool; weight : number; } | ||
|
||
class Car implements PhysicalObject { | ||
public intact = true; | ||
constructor(public color : Color, public weight : number) {}; | ||
} | ||
|
||
function scratch(aCar : Car) { | ||
typeCheck(JSVenv, arguments, schemas, ["PhysicalObject"]); | ||
console.log("Scratching the car!"); | ||
aCar.intact = false; | ||
} | ||
|
||
scratch(new Car(Color.BLACK, 4.2)); | ||
eval("scratch(new Car(Color.BLACK, 'four'));"); | ||
eval("scratch(69);"); | ||
eval("scratch({ intact: 42, color: Color.RED });"); |
This file contains 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,21 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var tsTempFile = null; | ||
['TMPDIR', 'TMP', 'TEMP'].forEach(function(td) { | ||
if (!tsTempFile && process.env[td]) | ||
tsTempFile = process.env[td]; | ||
}); | ||
tsTempFile = path.join((tsTempFile || "/tmp"), "ifacejson-jsproxy-tmp-" + Date.now() + ".js"); | ||
|
||
var contents = [ | ||
"(function() {", | ||
fs.readFileSync(path.join(__dirname, "ifacejson.js"), "utf8"), | ||
"module.exports = TSIFaceJSONSchema;", | ||
"}).call({});" | ||
].join(""); | ||
fs.writeFileSync(tsTempFile, contents, "utf-8"); | ||
|
||
module.exports = require(tsTempFile); | ||
|
||
fs.unlinkSync(tsTempFile); |
Oops, something went wrong.