Browse Source

cpplint.js file.{cc,h}

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
8a5194b7cf
  1. 73
      src/file.cc
  2. 73
      src/file.h

73
src/file.cc

@ -1,7 +1,5 @@
#include "node.h"
#include "file.h"
#include "events.h"
#include <string.h>
// Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
#include <file.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -9,9 +7,11 @@
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
namespace node {
using namespace v8;
using namespace node;
#define DEV_SYMBOL String::NewSymbol("dev")
#define INO_SYMBOL String::NewSymbol("ino")
@ -28,21 +28,17 @@ using namespace node;
#define CTIME_SYMBOL String::NewSymbol("ctime")
#define BAD_ARGUMENTS Exception::TypeError(String::New("Bad argument"))
void
EIOPromise::Attach (void)
{
void EIOPromise::Attach(void) {
ev_ref(EV_DEFAULT_UC);
Promise::Attach();
}
void
EIOPromise::Detach (void)
{
void EIOPromise::Detach(void) {
Promise::Detach();
ev_unref(EV_DEFAULT_UC);
}
Handle<Value> EIOPromise::New (const v8::Arguments& args) {
Handle<Value> EIOPromise::New(const v8::Arguments& args) {
HandleScope scope;
EIOPromise *promise = new EIOPromise();
@ -64,9 +60,7 @@ EIOPromise* EIOPromise::Create() {
static Persistent<FunctionTemplate> stats_constructor_template;
static Local<Object>
BuildStatsObject (struct stat * s)
{
static Local<Object> BuildStatsObject(struct stat * s) {
HandleScope scope;
Local<Object> stats =
@ -114,9 +108,7 @@ BuildStatsObject (struct stat * s)
return scope.Close(stats);
}
int
EIOPromise::After (eio_req *req)
{
int EIOPromise::After(eio_req *req) {
HandleScope scope;
EIOPromise *promise = reinterpret_cast<EIOPromise*>(req->data);
@ -202,9 +194,7 @@ EIOPromise::After (eio_req *req)
return 0;
}
static Handle<Value>
Close (const Arguments& args)
{
static Handle<Value> Close(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1 || !args[0]->IsInt32()) {
@ -216,9 +206,7 @@ Close (const Arguments& args)
return scope.Close(EIOPromise::Close(fd));
}
static Handle<Value>
Stat (const Arguments& args)
{
static Handle<Value> Stat(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1 || !args[0]->IsString()) {
@ -230,9 +218,7 @@ Stat (const Arguments& args)
return scope.Close(EIOPromise::Stat(*path));
}
static Handle<Value>
Rename (const Arguments& args)
{
static Handle<Value> Rename(const Arguments& args) {
HandleScope scope;
if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsString()) {
@ -248,8 +234,7 @@ Rename (const Arguments& args)
return scope.Close(promise->Handle());
}
static Handle<Value> Unlink (const Arguments& args)
{
static Handle<Value> Unlink(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1 || !args[0]->IsString()) {
@ -260,9 +245,7 @@ static Handle<Value> Unlink (const Arguments& args)
return scope.Close(EIOPromise::Unlink(*path));
}
static Handle<Value>
RMDir (const Arguments& args)
{
static Handle<Value> RMDir(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1 || !args[0]->IsString()) {
@ -273,9 +256,7 @@ RMDir (const Arguments& args)
return scope.Close(EIOPromise::RMDir(*path));
}
static Handle<Value>
MKDir (const Arguments& args)
{
static Handle<Value> MKDir(const Arguments& args) {
HandleScope scope;
if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsInt32()) {
@ -288,9 +269,7 @@ MKDir (const Arguments& args)
return scope.Close(EIOPromise::MKDir(*path, mode));
}
static Handle<Value>
ReadDir (const Arguments& args)
{
static Handle<Value> ReadDir(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1 || !args[0]->IsString()) {
@ -301,9 +280,7 @@ ReadDir (const Arguments& args)
return scope.Close(EIOPromise::ReadDir(*path));
}
static Handle<Value>
Open (const Arguments& args)
{
static Handle<Value> Open(const Arguments& args) {
HandleScope scope;
if ( args.Length() < 3
@ -328,9 +305,7 @@ Open (const Arguments& args)
* if null, write from the current position
* 3 encoding
*/
static Handle<Value>
Write (const Arguments& args)
{
static Handle<Value> Write(const Arguments& args) {
HandleScope scope;
if (args.Length() < 2 || !args[0]->IsInt32()) {
@ -363,9 +338,7 @@ Write (const Arguments& args)
* if null, read from the current position
* 3 encoding
*/
static Handle<Value>
Read (const Arguments& args)
{
static Handle<Value> Read(const Arguments& args) {
HandleScope scope;
if (args.Length() < 2 || !args[0]->IsInt32() || !args[1]->IsNumber()) {
@ -383,9 +356,7 @@ Read (const Arguments& args)
Persistent<FunctionTemplate> EIOPromise::constructor_template;
void
File::Initialize (Handle<Object> target)
{
void File::Initialize(Handle<Object> target) {
HandleScope scope;
NODE_SET_METHOD(target, "close", Close);
@ -414,3 +385,5 @@ File::Initialize (Handle<Object> target)
target->Set(String::NewSymbol("EIOPromise"),
EIOPromise::constructor_template->GetFunction());
}
} // end namespace node

73
src/file.h

@ -1,8 +1,9 @@
#ifndef node_file_h
#define node_file_h
// Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
#ifndef SRC_FILE_H_
#define SRC_FILE_H_
#include "node.h"
#include "events.h"
#include <node.h>
#include <events.h>
#include <v8.h>
namespace node {
@ -18,11 +19,11 @@ namespace node {
*/
#define NODE_V8_METHOD_DECLARE(name) \
static v8::Handle<v8::Value> name (const v8::Arguments& args)
static v8::Handle<v8::Value> name(const v8::Arguments& args)
class File {
public:
static void Initialize (v8::Handle<v8::Object> target);
public:
static void Initialize(v8::Handle<v8::Object> target);
};
class EIOPromise : public Promise {
@ -31,33 +32,31 @@ class EIOPromise : public Promise {
static v8::Persistent<v8::FunctionTemplate> constructor_template;
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Object>
Open (const char *path, int flags, mode_t mode)
{
static v8::Handle<v8::Object> Open(const char *path, int flags, mode_t mode) {
EIOPromise *p = Create();
p->req_ = eio_open(path, flags, mode, EIO_PRI_DEFAULT, After, p);
return p->handle_;
}
static v8::Handle<v8::Object>
Close (int fd)
{
static v8::Handle<v8::Object> Close(int fd) {
EIOPromise *p = Create();
p->req_ = eio_close(fd, EIO_PRI_DEFAULT, After, p);
return p->handle_;
}
static v8::Handle<v8::Object>
Write (int fd, void *buf, size_t count, off_t offset)
{
static v8::Handle<v8::Object> Write(int fd,
void *buf,
size_t count,
off_t offset) {
EIOPromise *p = Create();
p->req_ = eio_write(fd, buf, count, offset, EIO_PRI_DEFAULT, After, p);
return p->handle_;
}
static v8::Handle<v8::Object>
Read (int fd, size_t count, off_t offset, enum encoding encoding)
{
static v8::Handle<v8::Object> Read(int fd,
size_t count,
off_t offset,
enum encoding encoding) {
EIOPromise *p = Create();
p->encoding_ = encoding;
// NOTE: 2nd param: NULL pointer tells eio to allocate it itself
@ -65,49 +64,37 @@ class EIOPromise : public Promise {
return p->handle_;
}
static v8::Handle<v8::Object>
Stat (const char *path)
{
static v8::Handle<v8::Object> Stat(const char *path) {
EIOPromise *p = Create();
p->req_ = eio_stat(path, EIO_PRI_DEFAULT, After, p);
return p->handle_;
}
static v8::Handle<v8::Object>
Rename (const char *path, const char *new_path)
{
static v8::Handle<v8::Object> Rename(const char *path, const char *new_path) {
EIOPromise *p = Create();
p->req_ = eio_rename(path, new_path, EIO_PRI_DEFAULT, After, p);
return p->handle_;
}
static v8::Handle<v8::Object>
Unlink (const char *path)
{
static v8::Handle<v8::Object> Unlink(const char *path) {
EIOPromise *p = Create();
p->req_ = eio_unlink(path, EIO_PRI_DEFAULT, After, p);
return p->handle_;
}
static v8::Handle<v8::Object>
RMDir (const char *path)
{
static v8::Handle<v8::Object> RMDir(const char *path) {
EIOPromise *p = Create();
p->req_ = eio_rmdir(path, EIO_PRI_DEFAULT, After, p);
return p->handle_;
}
static v8::Handle<v8::Object>
MKDir (const char *path, mode_t mode)
{
static v8::Handle<v8::Object> MKDir(const char *path, mode_t mode) {
EIOPromise *p = Create();
p->req_ = eio_mkdir(path, mode, EIO_PRI_DEFAULT, After, p);
return p->handle_;
}
static v8::Handle<v8::Object>
ReadDir (const char *path)
{
static v8::Handle<v8::Object> ReadDir(const char *path) {
EIOPromise *p = Create();
// By using EIO_READDIR_DENTS (or other flags), more complex results can
// be had from eio_readdir. Doesn't seem that we need that though.
@ -117,18 +104,18 @@ class EIOPromise : public Promise {
protected:
void Attach ();
void Detach ();
void Attach();
void Detach();
EIOPromise () : Promise() { }
EIOPromise() : Promise() { }
private:
static int After (eio_req *req);
static int After(eio_req *req);
eio_req *req_;
enum encoding encoding_;
};
} // namespace node
#endif // node_file_h
} // namespace node
#endif // SRC_FILE_H_

Loading…
Cancel
Save