本文整理汇总了C++中Toplevel类的典型用法代码示例。如果您正苦于以下问题:C++ Toplevel类的具体用法?C++ Toplevel怎么用?C++ Toplevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Toplevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toString
// Execute the ToString algorithm as described in ECMA-262 Section 9.8.
// This is ToString(ToPrimitive(input argument, hint String))
// ToPrimitive(input argument, hint String) calls [[DefaultValue]]
// described in ECMA-262 8.6.2.6. The [[DefaultValue]] algorithm
// with hint String is inlined here.
Stringp ScriptObject::toString()
{
AvmCore *core = this->core();
Toplevel* toplevel = this->toplevel();
Atom atomv_out[1];
// call this.toString()
// NOTE use callers versioned public to get correct toString
Multiname tempname(core->findPublicNamespace(), core->ktoString);
atomv_out[0] = atom();
Atom result = toplevel->callproperty(atom(), &tempname, 0, atomv_out, vtable);
// if result is primitive, return its ToString
if (atomKind(result) != kObjectType)
return core->string(result);
// otherwise call this.valueOf()
tempname.setName(core->kvalueOf);
atomv_out[0] = atom();
result = toplevel->callproperty(atom(), &tempname, 0, atomv_out, vtable);
// if result is primitive, return it
if (atomKind(result) != kObjectType)
return core->string(result);
// could not convert to primitive.
toplevel->throwTypeError(kConvertToPrimitiveError, core->toErrorString(traits()));
return NULL; // unreachable
}
示例2: initPrototype
void ObjectClass::initPrototype()
{
// patch global.__proto__ = Object.prototype
Toplevel* toplevel = this->toplevel();
toplevel->setDelegate( prototype ); // global.__proto__ = Object.prototype
this->setDelegate( toplevel->classClass->prototype ); // Object.__proto__ = Class.prototype
}
示例3:
/*static*/ int CSysStatClass::fstat(ScriptObject* self, int fildes, CStatusObject* buf)
{
Toplevel* toplevel = self->toplevel();
if (!buf) {
toplevel->throwArgumentError(kNullArgumentError, "buf");
}
struct stat statbuf;
int result = VMPI_fstat( fildes, &statbuf );
if( result != -1 )
{
buf->set_st_dev( statbuf.st_dev );
buf->set_st_ino( statbuf.st_ino );
buf->set_st_mode( statbuf.st_mode );
buf->set_st_nlink( statbuf.st_nlink );
buf->set_st_uid( statbuf.st_uid );
buf->set_st_gid( statbuf.st_gid );
buf->set_st_rdev( statbuf.st_rdev );
buf->set_st_size( (double) statbuf.st_size );
buf->set_st_atime( (double) statbuf.st_atime );
buf->set_st_mtime( (double) statbuf.st_mtime );
buf->set_st_ctime( (double) statbuf.st_ctime );
}
return result;
}
示例4: VMPI_getprotoent
/*static*/ CprotoentObject* CNetdbClass::getprotoent(ScriptObject* self)
{
struct protoent *pp;
pp = VMPI_getprotoent();
if( pp )
{
ShellToplevel* shelltop = (ShellToplevel*)self->toplevel();
CprotoentClass *pc = shelltop->getShellClasses()->get_protoentClass();
CprotoentObject *po = pc->constructObject();
po->set_p_name( self->core()->newStringUTF8( pp->p_name ) );
po->set_p_proto( pp->p_proto );
Toplevel* toplevel = self->toplevel();
ArrayObject *aliases = toplevel->arrayClass()->newArray();
int count = 0;
int i;
for( i=0; pp->p_aliases[i] != NULL; ++i )
{
aliases->setUintProperty( count++, self->core()->newStringUTF8( pp->p_aliases[i] )->atom());
}
po->set_p_aliases( aliases );
return po;
}
return NULL;
}
示例5: initnamensx
Atom Stubs::do_abc_getpropnsx(MethodFrame* f, const Multiname* name, Atom ns,
Atom index, Atom object) {
Multiname tempname;
initnamensx(env(f), name, ns, index, &tempname);
Toplevel* t = toplevel(f);
return t->getproperty(object, &tempname, toVTable(t, object));
}
示例6: VMPI_setenv
/*static*/ int CStdlibClass::setenv(ScriptObject* self, Stringp name, Stringp value, bool overwrite)
{
Toplevel* toplevel = self->toplevel();
if( !name )
{
toplevel->throwArgumentError(kNullArgumentError, "name");
}
if( !value )
{
toplevel->throwArgumentError(kNullArgumentError, "value");
}
int writeover = 0;
if( overwrite ) { writeover = 1; }
#if AVMSYSTEM_WIN32
StUTF16String nameUTF16(name);
StUTF16String valueUTF16(value);
return VMPI_setenv16( nameUTF16.c_str(), valueUTF16.c_str(), writeover );
#else
StUTF8String nameUTF8(name);
StUTF8String valueUTF8(value);
return VMPI_setenv( nameUTF8.c_str(), valueUTF8.c_str(), writeover );
#endif
}
示例7: while
ArrayObject * ProgramClass::_getEnviron()
{
Toplevel *toplevel = this->toplevel();
AvmCore *core = this->core();
ArrayObject *array = toplevel->arrayClass()->newArray();
#if AVMSYSTEM_WIN32
wchar **cur = VMPI_GetEnviron16();
int i = 0;
while( cur[i] )
{
Stringp value = core->newStringUTF16(cur[i]);
StUTF8String valueUTF8(value);
array->setUintProperty( i, core->newStringUTF8( valueUTF8.c_str() )->atom() );
i++;
}
#else
char **cur = VMPI_GetEnviron();
int i = 0;
while( cur[i] )
{
array->setUintProperty( i, core->newStringUTF8( cur[i] )->atom() );
i++;
}
#endif
return array;
}
示例8: set_stack
bool SamplerScript::set_stack(ScriptObject* self, ClassFactoryClass* cf, const Sample& sample, SampleObject* sam)
{
if (sample.stack.depth > 0)
{
Toplevel* toplevel = self->toplevel();
AvmCore* core = toplevel->core();
Sampler* s = core->get_sampler();
StackFrameClass* sfcc = (StackFrameClass*)cf->get_StackFrameClass();
ArrayObject* stack = toplevel->arrayClass()->newArray(sample.stack.depth);
StackTrace::Element* e = (StackTrace::Element*)sample.stack.trace;
for(uint32_t i=0; i < sample.stack.depth; i++, e++)
{
StackFrameObject* sf = sfcc->constructObject();
// at every allocation the sample buffer could overflow and the samples could be deleted
// the StackTrace::Element pointer is a raw pointer into that buffer so we need to check
// that its still around before dereferencing e
uint32_t num;
if (s->getSamples(num) == NULL)
return false;
sf->setconst_name(e->name()); // NOT e->info()->name() because e->name() can be a fake name
sf->setconst_file(e->filename());
sf->setconst_line(e->linenum());
sf->setconst_scriptID(static_cast<double>(e->functionId()));
stack->setUintProperty(i, sf->atom());
}
sam->setconst_stack(stack);
}
return true;
}
示例9: free
/*static*/ int CStdlibClass::putenv(ScriptObject* self, Stringp name)
{
Toplevel* toplevel = self->toplevel();
if( !name )
{
toplevel->throwArgumentError(kNullArgumentError, "name");
}
#if AVMSYSTEM_WIN32
StUTF16String nameUTF16(name);
wchar * str = VMPI_strdup16( nameUTF16.c_str() );
int result = VMPI_putenv16( str );
#else
StUTF8String nameUTF8(name);
char * str = VMPI_strdup( nameUTF8.c_str() );
int result = VMPI_putenv( str );
#endif
/* note:
do not free() after strdup() or the string ref will be lost
so yeah it create a small memory leak
need to investigate if AVM2 intern string can solve this
or maybe create a special string pool to save such ref
that we could clean before the VM exit
*/
//VMPI_free(str);
return result;
}
示例10: VMPI_readdir
/*static*/ CdirentObject* CDirentClass::readdir(ScriptObject* self, CDIRObject* dirp)
{
Toplevel* toplevel = self->toplevel();
if( !dirp )
{
toplevel->throwArgumentError(kNullArgumentError, "dirp");
}
dirent *entry = VMPI_readdir( dirp->read() );
if( entry )
{
ShellToplevel* shelltop = (ShellToplevel*)self->toplevel();
CdirentClass *direc = shelltop->getShellClasses()->get_direntClass();
CdirentObject *direo = direc->constructObject();
direo->write( entry );
AvmCore *core = self->core();
direo->set_d_ino( entry->d_ino );
direo->set_d_name( core->newStringUTF8( entry->d_name ) );
return direo;
}
return NULL;
}
示例11: initnamex
Atom Stubs::do_abc_callpropx(MethodFrame* f, const Multiname* name, Atom index,
int argc, Atom* args) {
Multiname tempname;
initnamex(core(f), name, index, &tempname);
Toplevel* t = toplevel(f);
return t->callproperty(args[0], &tempname, argc - 1, args,
toVTable(t, args[0]));
}
示例12: getLengthProperty
uint32_t ScriptObject::getLengthProperty()
{
Toplevel* toplevel = this->toplevel();
AvmCore* core = toplevel->core();
Multiname mname(core->getAnyPublicNamespace(), core->klength);
Atom lenAtm = toplevel->getproperty(this->atom(), &mname, this->vtable);
return AvmCore::toUInt32(lenAtm);
}
示例13: setLengthProperty
void ScriptObject::setLengthProperty(uint32_t newLen)
{
Toplevel* toplevel = this->toplevel();
AvmCore* core = toplevel->core();
Multiname mname(core->getAnyPublicNamespace(), core->klength);
Atom lenAtm = core->uintToAtom(newLen);
toplevel->setproperty(this->atom(), &mname, lenAtm, this->vtable);
}
示例14: makeSample
ScriptObject* SamplerScript::makeSample(ScriptObject* self, ClassFactoryClass* cf, const Sample& sample)
{
Toplevel* toplevel = self->toplevel();
AvmCore* core = toplevel->core();
Sampler* s = core->get_sampler();
if (!s)
return NULL;
switch (sample.sampleType)
{
case Sampler::RAW_SAMPLE:
{
SampleClass* cls = (SampleClass*)cf->get_SampleClass();
SampleObject* sam = cls->constructObject();
sam->setconst_time(static_cast<double>(sample.micros));
if (!set_stack(self, cf, sample, sam))
return NULL;
return sam;
}
case Sampler::DELETED_OBJECT_SAMPLE:
{
DeleteObjectSampleClass* cls = (DeleteObjectSampleClass*)cf->get_DeleteObjectSampleClass();
DeleteObjectSampleObject* dsam = cls->constructObject();
dsam->setconst_time(static_cast<double>(sample.micros));
dsam->setconst_id(static_cast<double>(sample.id));
dsam->setconst_size(static_cast<double>(sample.size));
return dsam;
}
case Sampler::NEW_OBJECT_SAMPLE:
{
NewObjectSampleClass* cls = (NewObjectSampleClass*)cf->get_NewObjectSampleClass();
NewObjectSampleObject* nsam = cls->constructObject();
nsam->setconst_time(static_cast<double>(sample.micros));
nsam->setconst_id(static_cast<double>(sample.id));
if (!set_stack(self, cf, sample, nsam))
return NULL;
if (sample.ptr != NULL )
nsam->setRef((AvmPlusScriptableObject*)sample.ptr);
nsam->setconst_type(getType(toplevel, sample.sot, sample.ptr));
nsam->setSize(sample.alloc_size);
return nsam;
}
case Sampler::NEW_AUX_SAMPLE:
{
NewObjectSampleClass* cls = (NewObjectSampleClass*)cf->get_NewObjectSampleClass();
NewObjectSampleObject* nsam = cls->constructObject();
nsam->setconst_time(static_cast<double>(sample.micros));
nsam->setconst_id(static_cast<double>(sample.id));
if (!set_stack(self, cf, sample, nsam))
return NULL;
nsam->setSize(sample.alloc_size);
return nsam;
}
}
AvmAssert(0);
return NULL;
}
示例15: callProperty
// this = argv[0] (ignored)
// arg1 = argv[1]
// argN = argv[argc]
Atom ScriptObject::callProperty(const Multiname* multiname, int argc, Atom* argv)
{
Toplevel* toplevel = this->toplevel();
Atom method = getMultinameProperty(multiname);
if (!AvmCore::isObject(method))
toplevel->throwTypeError(kCallOfNonFunctionError, core()->toErrorString(multiname));
argv[0] = atom(); // replace receiver
return toplevel->op_call(method, argc, argv);
}