Comparing version 0.0.3 to 0.1.0
@@ -5,3 +5,3 @@ { | ||
"description": "Duktape for node.js", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"main": "./index.js", | ||
@@ -8,0 +8,0 @@ "license": "MIT", |
@@ -13,3 +13,3 @@ duktape-node | ||
### run(functionName, parameter, script, callback) | ||
### run(functionName, parameter, script, apiObject, callback) | ||
**Description** | ||
@@ -24,2 +24,6 @@ | ||
* script: whole javascript source of script (string) | ||
* apiObject: API for script (object) | ||
* properties: | ||
* key: name for function | ||
* value: function to call | ||
* callback: function with signature `function(error, returnValue)` | ||
@@ -33,11 +37,19 @@ * error: error status (boolean) | ||
var script = " | ||
function helloFun(parameterString) { | ||
return { | ||
value: 'hello ' + parameterString, | ||
extra: 'bye ' + parameterString | ||
}; | ||
var apiFunction = function(name) { | ||
return "hello " + name; | ||
} | ||
var script = " \ | ||
function helloFun(parameterString) { \ | ||
return { \ | ||
value: hello(parameterString), \ | ||
extra: 'bye ' + parameterString \ | ||
}; \ | ||
}"; | ||
var apiObject = { | ||
hello: apiFunction | ||
}; | ||
duktape.run("helloFun", "world", script, function(error, ret) { | ||
duktape.run("helloFun", "world", script, apiObject, function(error, ret) { | ||
if(error) { | ||
@@ -53,3 +65,3 @@ console.log("got error: " + ret); | ||
### runSync(functionName, parameter, script, callback) | ||
### runSync(functionName, parameter, script, apiObject) | ||
@@ -65,2 +77,6 @@ **Description** | ||
* script: whole javascript source of script (string) | ||
* apiObject: API for script (object) | ||
* properties: | ||
* key: name for function | ||
* value: function to call | ||
@@ -71,12 +87,20 @@ **Example** | ||
var script = " | ||
function helloFun(parameterString) { | ||
return { | ||
value: 'hello ' + parameterString, | ||
extra: 'bye ' + parameterString | ||
}; | ||
var apiFunction = function(name) { | ||
return "hello " + name; | ||
} | ||
var apiObject = { | ||
hello: apiFunction | ||
}; | ||
var script = " \ | ||
function helloFun(parameterString) { \ | ||
return { \ | ||
value: hello(parameterString), \ | ||
extra: 'bye ' + parameterString \ | ||
}; \ | ||
}"; | ||
try { | ||
var ret = duktape.runSync("helloFun", "world", script); | ||
var ret = duktape.runSync("helloFun", "world", script, apiObject); | ||
var retVal = JSON.parse(ret); | ||
@@ -99,3 +123,3 @@ console.log(retVal.value); | ||
## Known issues | ||
* Probably does not compile on Windows | ||
* No possilibity for defining external APIs, that would be accessible from scripts. | ||
* Probably does not compile on other compilers than gcc (has been tested on linux/gcc4.8.1). | ||
var equal = require('assert').equal, | ||
duktape = require('../index'); | ||
describe('Duktape', function () { | ||
describe('Duktape basic', function () { | ||
@@ -13,3 +13,3 @@ it('should run a script (sync)', function (finished) { | ||
var ret = duktape.runSync("test", "", script); | ||
equal(ret, 2) | ||
equal(ret, 2); | ||
finished(); | ||
@@ -24,3 +24,3 @@ }); | ||
"; | ||
duktape.run("test", "", script, function(error, ret) { | ||
duktape.run("test", "", script, null, function(error, ret) { | ||
equal(error, false); | ||
@@ -56,3 +56,3 @@ equal(ret, 2); | ||
"; | ||
duktape.run("test", "", script, function(error, ret) { | ||
duktape.run("test", "", script, null, function(error, ret) { | ||
equal(error, true); | ||
@@ -102,3 +102,3 @@ finished(); | ||
{ | ||
var ret = duktape.run(true, "", "", function() {}); | ||
var ret = duktape.run(true, "", "", null, function() {}); | ||
} catch (error) { | ||
@@ -115,3 +115,3 @@ equal(error, "TypeError: Wrong arguments"); | ||
{ | ||
var ret = duktape.run("", 1, "", function() {}); | ||
var ret = duktape.run("", 1, "", null, function() {}); | ||
} catch (error) { | ||
@@ -128,3 +128,3 @@ equal(error, "TypeError: Wrong arguments"); | ||
{ | ||
var ret = duktape.run("", "", 123, function() {}); | ||
var ret = duktape.run("", "", 123, null, function() {}); | ||
} catch (error) { | ||
@@ -153,3 +153,3 @@ equal(error, "TypeError: Wrong arguments"); | ||
{ | ||
var ret = duktape.run("", "", "", ""); | ||
var ret = duktape.run("", "", "", null, ""); | ||
} catch (error) { | ||
@@ -156,0 +156,0 @@ equal(error, "TypeError: Wrong arguments"); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2250063
19
243
119