Well, like a said before, the std::ostream object is not the problem, if i 
change the method to:

v8::Handle<v8::Value> System::log(const v8::Arguments& args)
{
    for(int i = 0, s = args.Length(); i < s; ++i) {
        v8::String::AsciiValue ascii(args[i]);
        std::cerr << "Length: " << ascii.length() << std::endl;
        std::cerr.write(*ascii,ascii.length()) << std::endl;
    }
    return v8::Undefined();
}

Will it print out the length without any whitespaces, e.g javascript code: 
System.log("      "); prints "Length: 0". However, do anyone have any idea 
what I can have done wrong? I am adding the method by doing something like 
the following, if it helps:

Handlescope handle_scope;
Persistent<Context> context = context(Context::New());
Context::Scope context_scope(context);
Local<ObjectTemplate> env = ObjectTemplate::New();
env->Set(String::New("log"), FunctionTemplate::New(&System::log)); 
//System.log is a static method of course
context->Global()->Set(String::New("System"), env->NewInstance());



Den onsdagen den 2:e maj 2012 kl. 02:47:52 UTC+2 skrev idleman:
>
> Why does all white spaces get removed in the example below?
>
> //C++
> Handle<Value> System::log(const Arguments& args)
> {
>     for(int i = 0, s = args.Length(); i < s; ++i) {
>        String::AsciiValue ascii(args[i]);
>         os.write(*ascii, ascii.length()) << std::endl; //os = 
> std::ostream& object
>     }
>     return Undefined();
> }
>
> //Then in javascript, there the System object have been "exposed" to 
> JavaScript.
> System.log("How are you?");  //prints "howareyou?" not "how are you?", e.g 
> no whitespaces
>
> In the example do I get the text: "Howareyou?", not "How are you?", what 
> does I wrong? Why are all white spaces removed? The std::ostream::write 
> write oformatted output, so it does not remove any white space, so it is 
> not the problem.
>
> Thanks in advance!
>
>

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to