Permalink
Browse files

Added documentation comments, walkthrough dir, made coffeescript buil…

…tin.
  • Loading branch information...
1 parent 719e0ef commit b13f35e9029655811e0583bb10d01605044f41e3 Michael Schwartz committed Mar 19, 2012
View
@@ -3,6 +3,7 @@
include('builtin/print_r.js');
include('builtin/extensions.js');
include('builtin/Exceptions.js');
+include('builtin/coffee-script.js');
include('builtin/include.js');
include('builtin/require.js');
include('builtin/xhr.js');
File renamed without changes.
View
@@ -96,6 +96,7 @@
require.fsPath = '';
require.cache = {};
require.path = [
+ './',
'modules',
'/usr/share/silkjs/modules'
];
View
@@ -147,6 +147,7 @@ HttpChild = (function() {
return found;
}
function handleRequest() {
+ req.script_path = req.uri;
delete req.path_info;
var parts = req.uri.substr(1).split('/');
if (parts[0].length == 0) {
@@ -202,6 +203,7 @@ HttpChild = (function() {
notFound();
}
+ req.script_path = fn.replace(/\index\..*$/, '').replace(fs.realpath(Config.documentRoot), '');
res.status = 200;
req.path = fn;
parts = fn.split('.');
View
@@ -1,9 +1,6 @@
#!/usr/local/bin/silkjs
// httpd/main.js
-include('lib/coffee-script.js');
-
-
print_r = require('builtin/print_r');
console = require('console');
fs = require('builtin/fs');
@@ -44,13 +41,7 @@ function main() {
return false;
}
});
- var pid;
- var fd = fs.open(Config.lockFile, fs.O_WRONLY|fs.O_CREAT|fs.O_TRUNC, 0644);
- fs.close(fd);
- var serverSocket = net.listen(Config.port);
- logfile.init();
-
if (debugMode) {
v8.enableDebugger();
log('Running in debug mode');
@@ -60,6 +51,14 @@ function main() {
include(arg);
}
});
+
+ var pid;
+ var fd = fs.open(Config.lockFile, fs.O_WRONLY|fs.O_CREAT|fs.O_TRUNC, 0644);
+ fs.close(fd);
+ var serverSocket = net.listen(Config.port);
+
+ logfile.init();
+
if (debugMode) {
while (1) {
HttpChild.run(serverSocket, process.getpid());
View
@@ -7,7 +7,7 @@
var mysql = require('builtin/mysql');
- exports.MySQL = MySQL = function() {
+ var MySQL = exports.MySQL = function() {
this.queryCount = 0;
this.connected = false;
};
@@ -885,7 +885,6 @@ function for_side_effects(ast, handler) {
"for-in": found,
"while": found,
"do": found,
- "return": found,
"unary-prefix": unary,
"unary-postfix": unary,
"defun": found
View
@@ -1,5 +1,5 @@
(function() {
- console = builtin.console;
+ var console = builtin.console;
print_r = require('builtin/print_r');
exports = {
log: console.log,
View
@@ -51,6 +51,11 @@ function processFile(fn) {
content,
params;
while ((line = readLine(lines)) !== false) {
+ if (line === '/** @ignore */') {
+ return [{
+ tag: 'ignore'
+ }];
+ }
//console.log('line: ' + line);
if (line.search(/\s*\/\*\*/) == -1) {
continue;
@@ -67,6 +72,7 @@ function processFile(fn) {
case 'function':
case 'class':
case 'singleton':
+ case 'namespace':
case 'module':
item.tag = tag;
item.name = parts.join(' ');
@@ -87,6 +93,9 @@ function processFile(fn) {
item.tag = tag;
content += parts.join(' ') + '\n';
break;
+ case '@ignore':
+ item.tag = tag;
+ break;
default:
content += line + '\n';
break;
View
@@ -1,3 +1,4 @@
+/** @ignore */
#include "SilkJS.h"
static const std::string base64_chars =
View
@@ -1,3 +1,4 @@
+/** @ignore */
/*
* Berkley Database (BDB) Interface
*/
View
@@ -1,5 +1,33 @@
+/**
+ * @module builtin/buffer
+ *
+ * ### Synopsis
+ * SilkJS builtin buffer object.
+ *
+ * ### Description
+ * The builtin/buffer object provides a growable byte buffer for strings and binary data.
+ *
+ * Buffers should be treated as opaque handles in JavaScript code. The builtin/buffer functions take this opaque handle as the first argument. The exception, of course, is the buffer.create() method, which creates a new buffer.
+ *
+ * ### Usage
+ * var buffer = require('builtin/buffer');
+ *
+ * ### See Also
+ * builtin/net.writeBuffer()
+ */
#include "SilkJS.h"
+/**
+ * @function buffer.create
+ *
+ * ### Synopsis
+ *
+ * var buf = buffer.create();
+ *
+ * Creates a new buffer. Buffers created with buffer.create() should be released by calling buffer.destroy() when you are finished with the buffer.
+ *
+ * @return {object} buf - opaque handel to newly created buffer.
+ */
static JSVAL buffer_create(JSARGS args) {
HandleScope scope;
Buffer *buf = new Buffer;
@@ -12,6 +40,17 @@ static JSVAL buffer_create(JSARGS args) {
return scope.Close(External::New(buf));
}
+/**
+ * @function buffer.reset
+ *
+ * ### Synopsis
+ *
+ * buffer.reset(buf);
+ *
+ * Reset a buffer to "empty" state.
+ *
+ * @param {object} buf - buffer to reset
+ */
static JSVAL buffer_reset(JSARGS args) {
HandleScope scope;
Local<External>wrap = Local<External>::Cast(args[0]);
@@ -25,6 +64,17 @@ static JSVAL buffer_reset(JSARGS args) {
return Undefined();
}
+/**
+ * @function buffer.destroy
+ *
+ * ### Synopsis
+ *
+ * buffer.destroy(buf);
+ *
+ * Free a previously created buffer. Buffers allocate system resources that will not be freed until this function is called.
+ *
+ * @param {object} buf - buffer to free.
+ */
static JSVAL buffer_destroy(JSARGS args) {
HandleScope scope;
Local<External>wrap = Local<External>::Cast(args[0]);
@@ -36,6 +86,17 @@ static JSVAL buffer_destroy(JSARGS args) {
return Undefined();
}
+/**
+ * @function buffer.write
+ *
+ * ### Synopsis
+ * buffer.write(buf, str);
+ *
+ * Write a string into the specified buffer.
+ *
+ * @param {object} buf - buffer to write string to.
+ * @param {string{ str - string to add to buffer.
+ */
static JSVAL buffer_write(JSARGS args) {
HandleScope scope;
Local<External>wrap = Local<External>::Cast(args[0]);
@@ -58,6 +119,18 @@ static JSVAL buffer_write(JSARGS args) {
return Undefined();
}
+/**
+ * @function buffer.write64
+ *
+ * ### Synopsis
+ *
+ * buffer.write64(buf, base64String)
+ *
+ * Write a base64 encoded string to buffer, decoding the base64 to binary. This function writes binary data to the buffer.
+ *
+ * @param {object} buf - buffer to write to.
+ * @param {string} base64Str - base64 encoded binary data to add to buffer as binary.
+ */
static JSVAL buffer_write64(JSARGS args) {
HandleScope scope;
Local<External>wrap = Local<External>::Cast(args[0]);
@@ -67,6 +140,16 @@ static JSVAL buffer_write64(JSARGS args) {
return Undefined();
}
+/**
+ * @function buffer.read
+ *
+ * var contents = buffer.read(buf);
+ *
+ * Return contents of buffer as a JavaScript string.
+ *
+ * @param {object} buf - buffer to get contents of.
+ * @return {string s - buffer contents as JavaScript string.
+ */
static JSVAL buffer_read(JSARGS args) {
HandleScope scope;
Local<External>wrap = Local<External>::Cast(args[0]);
@@ -78,6 +161,18 @@ static JSVAL buffer_read(JSARGS args) {
#endif
}
+/**
+ * @function buffer.size
+ *
+ * ### Synopsis
+ *
+ * var size = buffer.size(buf);
+ *
+ * Get count of bytes in a buffer.
+ *
+ * @param {object} buf - buffer to get size of.
+ * @return {int} size - size of buffer in bytes.
+ */
static JSVAL buffer_size(JSARGS args) {
HandleScope scope;
Local<External>wrap = Local<External>::Cast(args[0]);
View
@@ -1,14 +1,50 @@
-// see http://invisible-island.net/ncurses/man/ncurses.3x.html
-
+/**
+ * @module builtin/console
+ *
+ * ### Synopsis
+ * SilkJS builtin console object.
+ *
+ * ### Description
+ * The builtin/console object provides a minimal implementation of the client-side console object.
+ *
+ * ### Usage
+ * var console = require('builtin/console');
+ *
+ * ### See Also
+ * The JavaScriptimplementation of a more robust console object:
+ * modules/console.js
+ */
#include "SilkJS.h"
+/**
+ * @function console.log
+ *
+ * ### Synopsis
+ *
+ * console.log(s);
+ *
+ * Write a string to stdout.
+ *
+ * @param {string} s - the string to write to stdout
+ */
static JSVAL log(JSARGS args) {
HandleScope scope;
String::AsciiValue s(args[0]);
fprintf(stdout, "%s\n", *s);
return Undefined();
}
+/**
+ * @function console.e
+ *
+ * ### Synopsis
+ *
+ * console.error(s);
+ *
+ * Write a string to stderr.
+ *
+ * @param {string} s - the string to write to stderr
+ */
static JSVAL error(JSARGS args) {
HandleScope scope;
String::AsciiValue s(args[0]);
View
@@ -1,3 +1,21 @@
+/**
+ * @module builtin/xhrhelper
+ *
+ * ### Synopsis
+ * SilkJS builtin xhrhelper object.
+ *
+ * ### Description
+ * The builtin/xhrhelper object provides a minimal interface to the curl library - enough for implementation of XMLHttpRequest object for SilkJS.
+ *
+ * It is not expected that application code will use these methods directly.
+ *
+ * ### Usage
+ * var xhrhelper = require('builtin/xhrhelper');
+ *
+ * ### See Also
+ * The JavaScriptimplementation of a more robust console object:
+ * modules/console.js
+ */
#include "SilkJS.h"
#include <curl/curl.h>
@@ -19,6 +37,34 @@ static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, voi
return realsize;
}
+/**
+ * @function xhrhelper.request
+ *
+ * ### Synopsis
+ *
+ * var o = xhrhelper.request(config);
+ *
+ * Perform a curl request.
+ *
+ * ### Description
+ *
+ * The config object looks like this:
+ * + method: "POST" (or "GET")
+ * + url: "http://example.com/example_url"
+ * + data: javascript_object
+ *
+ * The data member is only handled if the method is "POST" - the data object is a key/value pair of items to post to the remote host.
+ *
+ * The returned object is the original object with three additional members added:
+ * + status: http status of reponse (an int, such as 200 for OK)
+ * +_contentType: the content-type/mime-type as a string
+ * + reponseTExt: the body of the response
+ *
+ * On error, a string containing the error information is returned instead of an object.
+ *
+ * @param {object} config - confiuration object, see above.
+ * @return {object} o - status/response, see above.
+ */
static JSVAL request(JSARGS args) {
HandleScope scope;
Handle<Object>o = args[0]->ToObject();
View
@@ -1,4 +1,4 @@
-/**
+/* *
* @module builtin/gd
*
* ### Synopsis
Oops, something went wrong.

0 comments on commit b13f35e

Please sign in to comment.