Hi, all!
i'm working on ToSource() functionality for v8. i've got it working
for native types but i've run into a slight stumbling block for
converting Objects to source code.
i know i can fetch all properties of an object with
Object::GetPropertyNames(). That fetches *all* properties, including
from the prototype. When looping over those, is
Object::HasRealNamedProperty() a mechanism i can use to determine if
the property is from the prototype (which i don't want to output) or
directly in the object (in which case i do want to output it)?
For those unfamiliar with toSource() (a standard feature in
SpiderMonkey), it's like toString() but converts the object ot eval
()'able JS source code. e.g.:
int test_tosource( )
{
using namespace v8;
using namespace v8::juice;
using namespace v8::juice::convert;
CERR << ToSource( 43 )
<< '\n' << ToSource( "He's one of us, isn't he?" )
<< '\n' << ToSource( "He said, \"hi!\"" )
<< '\n' << ToSource( "He said, \"she's not home!\"" )
<< '\n';
typedef std::list<std::string> SL;
SL li;
li.push_back( "He's one of us, isn't he?" );
li.push_back( "He said, \"hi!\"" );
li.push_back( "He said, \"she's not home!\"" );
CERR << ToSource(li) << '\n';
std::list<SL> lili;
lili.push_back(li);
lili.push_back(li);
lili.push_back(li);
CERR << ToSource(lili) << '\n';
return 0;
}
Outputs:
shell.cc:176 : 43
"He's one of us, isn't he?"
'He said, "hi!"'
'He said, "she\'s not home!"'
shell.cc:187 : ["He's one of us, isn't he?", 'He said, "hi!"', 'He
said, "she\'s not home!"']
shell.cc:192 : [["He's one of us, isn't he?", 'He said, "hi!"', 'He
said, "she\'s not home!"']
, ["He's one of us, isn't he?", 'He said, "hi!"', 'He said, "she\'s
not home!"']
, ["He's one of us, isn't he?", 'He said, "hi!"', 'He said, "she\'s
not home!"']
]
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---