Changeset 19137

Show
Ignore:
Timestamp:
09/10/08 22:29:55 (6 years ago)
Author:
tokuhirom
Message:

added File.write

Location:
lang/cplusplus/fcgi-v8/trunk
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • lang/cplusplus/fcgi-v8/trunk/src/file.cc

    r19135 r19137  
    5050} 
    5151 
     52v8::Handle<v8::Value> _write(const v8::Arguments& args) { 
     53    if (args.Length() != 1) { 
     54        return v8::ThrowException(v8::String::New("Exception: missing args: write(str)")); 
     55    } 
     56    v8::HandleScope handle_scope; 
     57    v8::Local<v8::Value> field = args.This()->GetInternalField(0); 
     58    if (!field->IsExternal()) { 
     59        return v8::ThrowException(v8::String::New("Exception: file handle")); 
     60    } 
     61    FILE *fh = reinterpret_cast<FILE *>(v8::Handle<v8::External>::Cast(field)->Value()); 
     62    if (!fh) { 
     63        return v8::ThrowException(v8::String::New("Exception: file handle")); 
     64    } 
     65    v8::String::AsciiValue str(args[0]); 
     66    size_t wrote = fwrite(*str, sizeof(char), args[0]->ToString()->Length(), fh); 
     67    return Int32::New(wrote); 
     68} 
     69 
    5270v8::Handle<v8::Value> _close(const v8::Arguments& args) { 
    5371    if (args.Length() != 0) { 
     
    7997    ot->Set(String::New("close"), FunctionTemplate::New(_close)); 
    8098    ot->Set(String::New("read"),  FunctionTemplate::New(_read)); 
     99    ot->Set(String::New("write"), FunctionTemplate::New(_write)); 
    81100 
    82101    ot->SetInternalFieldCount(1);