void HTTPFormClass::saveFile(Stringp key, Stringp destPath) { string sKey(((StUTF8String) key).c_str()); for (std::vector<FormFile>::iterator it=sapi->files.begin(); it!=sapi->files.end(); it++) { if (sKey == (*it).name) { StUTF8String filenameUTF8(destPath); File* fp = Platform::GetInstance()->createFile(); if (!fp || !fp->open(filenameUTF8.c_str(), File::OPEN_WRITE)) { if(fp) { Platform::GetInstance()->destroyFile(fp); } toplevel()->throwError(kFileWriteError, destPath); } if ((int32_t)fp->write((*it).data.data(), (*it).data.length()) != (int32_t)(*it).data.length()) toplevel()->throwError(kFileWriteError, destPath); fp->close(); Platform::GetInstance()->destroyFile(fp); } } }
avmplus::ArrayObject * CSocketClass::__gethostbyaddr(avmplus::Stringp addr, bool numeric) { if (!addr) { toplevel()->throwArgumentError(kNullArgumentError, "addr"); } avmplus::StUTF8String addrUTF8(addr); avmplus::ArrayObject *list = toplevel()->arrayClass()->newArray(); int count = 0; struct in_addr **addr_list; struct hostent *host; host = VMPI_gethostbyaddr( addrUTF8.c_str() ); if(host != NULL) { if(numeric) { addr_list = (struct in_addr **)host->h_addr_list; int i; for(i = 0; addr_list[i] != NULL; i++) { list->setUintProperty(i, core()->newStringUTF8( inet_ntoa(*addr_list[i]) )->atom()); } } else { list->setUintProperty(count++, core()->newStringUTF8( host->h_name )->atom()); if(host->h_aliases) { int x; for(x=0; host->h_aliases[x]; ++x) { list->setUintProperty(count++, core()->newStringUTF8( host->h_aliases[x] )->atom()); } } } } return list; }
ArrayObject* StringClass::_split(Stringp in, Atom delimAtom, uint32 limit) { AvmCore* core = this->core(); if (limit == 0) return toplevel()->arrayClass->newArray(); if (in->length() == 0) { ArrayObject* out = toplevel()->arrayClass->newArray(); out->setUintProperty(0,in->atom()); return out; } // handle RegExp case if (AvmCore::istype(delimAtom, core->traits.regexp_itraits)) { RegExpObject *reObj = (RegExpObject*) AvmCore::atomToScriptObject(delimAtom); return reObj->split(in, limit); } ArrayObject *out = toplevel()->arrayClass->newArray(); Stringp delim = core->string(delimAtom); int ilen = in->length(); int dlen = delim->length(); int count = 0; if (dlen <= 0) { // delim is empty string, split on each char for (int i = 0; i < ilen && (unsigned)i < limit; i++) { Stringp sub = in->substr(i, 1); out->setUintProperty(count++, sub->atom()); } return out; } int32_t start = 0; while (start <= in->length()) { if ((limit != 0xFFFFFFFFUL) && (count >= (int) limit)) break; int32_t bgn = in->indexOf(delim, start); if (bgn < 0) // not found, use the string remainder bgn = in->length(); Stringp sub = in->substring(start, bgn); out->setUintProperty(count++, sub->atom()); start = bgn + delim->length(); } return out; }
void Interpret(char expr[]) { SetIntSignal(True); if(commandline(expr)) ; else if(seterror()==0) { initstack(); restoretemplates(); CloseAllIOFiles(); interrupted = False; if(parseinput(expr)) checkexpression(top(), True); else { checkexpression(top(), False); settop(modify_expression(top())); starttiming(); toplevel(); stoptiming(); } } SetIntSignal(False); initstack(); restoretemplates(); CloseAllIOFiles(); interrupted = False; Write("\n"); }
void SystemClass::trace(ArrayObject* a) { if (!a) toplevel()->throwArgumentError(kNullArgumentError, "array"); AvmCore* core = this->core(); PrintWriter& console = core->console; for (int i=0, n = a->getLength(); i < n; i++) { if (i > 0) console << ' '; Stringp s = core->string(a->getUintProperty(i)); for (int j = 0; j < s->length(); j++) { wchar c = (*s)[j]; // '\r' gets converted into '\n' // '\n' is left alone // '\r\n' is left alone if (c == '\r') { if (((j+1) < s->length()) && (*s)[j+1] == '\n') { console << '\r'; j++; } console << '\n'; } else { console << c; } } } console << '\n'; }
int main(int argc, char *argv[]) { FILE *f = stdin; char *rc_file = absolute_path(RC_FILE); char *hist_file = absolute_path(HIST_FILE); if (argc > 1) { /* On travaille sur un shell script: lui passer les arguments et le lancer */ add_program_parameters_environ(argc-1, argv+1); return execute_script(argv[1]); } else { /* Imprimer une bannière */ fprintf(stderr, "Bienvenue sur %s version %s\n", SHELL_NAME, VERSION); /* lancer éventuellement le script d'initialisation de l'utilisateur*/ if (access(rc_file, R_OK) == 0) execute_script(rc_file); /* Passer les paramètres (ici 0 param) et appeler le toplevel de l'interprete */ add_program_parameters_environ(1, argv); /* Gérer l'historique (la sauvegarde se fera automatiquement) */ init_history(HISTORY_DEFAULT_SIZE, hist_file); /* Lancement du toplevel de l'interprète */ toplevel(f); fprintf(stderr, "Bye\n"); } return EXIT_SUCCESS; }
/** 15.2.4.5 Object.prototype.hasOwnProperty (V) When the hasOwnProperty method is called with argument V, the following steps are taken: 1. Let O be this object. 2. Call ToString(V). 3. If O doesn't have a property with the name given by Result(2), return false. 4. Return true. NOTE Unlike [[HasProperty]] (section 8.6.2.4), this method does not consider objects in the prototype chain. */ bool ObjectClass::_hasOwnProperty(Atom thisAtom, Stringp name) { AvmCore* core = this->core(); name = name ? core->internString(name) : (Stringp)core->knull; Traitsp t = NULL; switch (atomKind(thisAtom)) { case kObjectType: { // ISSUE should this look in traits and dynamic vars, or just dynamic vars. ScriptObject* obj = AvmCore::atomToScriptObject(thisAtom); // TODO // The change below is important as otherwise we will throw error in a call to hasAtomProperty for ByteArrayObject. // This gets us back to the behaviour which we had in Marlin. // A bugzilla bug [ 562224 ] has been created to address this issue more cleanly in near future return obj->traits()->getTraitsBindings()->findBinding(name, core->findPublicNamespace()) != BIND_NONE || obj->hasStringProperty(name); } case kNamespaceType: case kStringType: case kBooleanType: case kDoubleType: case kIntptrType: t = toplevel()->toTraits(thisAtom); break; default: return false; } // NOTE use caller's public namespace return t->getTraitsBindings()->findBinding(name, core->findPublicNamespace()) != BIND_NONE; }
// memory changed so go through and update all reference to both the base // and the size of the global memory void DomainEnv::notifyGlobalMemoryChanged(uint8_t* newBase, uint32_t newSize) { AvmAssert(newBase != NULL); // real base address AvmAssert(newSize >= GLOBAL_MEMORY_MIN_SIZE); // big enough if (newSize < GLOBAL_MEMORY_MIN_SIZE) { newBase = m_globalMemoryScratch->scratch; newSize = GLOBAL_MEMORY_MIN_SIZE; } m_globalMemoryBase = newBase; // We require that MOps addresses be non-negative int32 values. // Furthermore, the bounds checks may fail to detect an out-of-bounds // access if the global memory size is not itself a non-negative int32. // See bug 723401. Since the size of a byte array may expand as // side-effect of other operations according to a policy not under direct // control of the user, it is not appropriate to signal an error here. // We simply silently ignore any excess allocation. // TODO: While we cannot do much about automatic resizing, an attempt // to explicitly set the size too large should throw an exception before // arriving here. m_globalMemorySize = (newSize > 0x7fffffff) ? 0x7fffffff : newSize; TELEMETRY_UINT32(toplevel()->core()->getTelemetry(), ".mem.bytearray.alchemy",m_globalMemorySize/1024); }
static int emit_csource(void) { AST* tree = NULL; Parser* ctx = parser_new(NULL, stdin); while(NULL != (tree = normalize(toplevel(ctx)))) codegen(stdout, tree); return 0; }
Traits *DomainObject::getTraits (Atom a) { if (ISNULL(a)) { return core()->traits.null_itraits; } if (a == kSpecialType) { return core()->traits.void_itraits; } switch (a & 7) { case kObjectType: return AvmCore::atomToScriptObject(a)->traits(); case kNamespaceType: return core()->traits.namespace_itraits; case kStringType: return core()->traits.string_itraits; case kBooleanType: return core()->traits.boolean_itraits; case kIntegerType: return core()->traits.int_itraits; case kDoubleType: return core()->traits.number_itraits; } toplevel()->throwArgumentError(kNotImplementedError, core()->toErrorString("value")); return core()->traits.void_itraits; }
//new adds 11 Stringp NativeWindowObject::AS3_renderMode_get() { // LOGWHERE(); if(m_pInitOptions) return m_pInitOptions->AS3_renderMode_get();//Stringp("auto");// return ((ShellToplevel*)toplevel())->getNativeWindowRenderModeClass()->getSlotAUTO(); }
Stringp ProgramClass::_popenRead(Stringp command) { if( !command ) { toplevel()->throwArgumentError(kNullArgumentError, "command"); } StUTF8String commandUTF8(command); FILE *read_fp; char buffer[BUFSIZ + 1]; int chars_read; VMPI_memset(buffer, '\0', sizeof(buffer)); read_fp = VMPI_popen(commandUTF8.c_str(), "r"); Stringp output = core()->newStringUTF8( "" ); if (read_fp != NULL) { chars_read = (int) fread(buffer, sizeof(char), BUFSIZ, read_fp); output = output->append( core()->newStringUTF8(buffer, chars_read) ); while(chars_read > 0) { buffer[chars_read - 1] = '\0'; chars_read = (int) fread(buffer, sizeof(char), BUFSIZ, read_fp); output = output->append( core()->newStringUTF8(buffer, chars_read) ); } VMPI_pclose(read_fp); return output; } return NULL; }
void Stubs::do_abc_setpropnsx(MethodFrame* f, const Multiname* name, Atom ns, Atom index, Atom object, Atom value) { Multiname tempname; initnamensx(env(f), name, ns, index, &tempname); Toplevel* t = toplevel(f); t->setproperty(object, &tempname, value, toVTable(t, object)); }
NamespaceClass::NamespaceClass(VTable* cvtable) : ClassClosure(cvtable) { toplevel()->_namespaceClass = this; AvmAssert(traits()->getSizeOfInstance() == sizeof(NamespaceClass)); createVanillaPrototype(); }
Atom ScriptObject::getAtomPropertyFromProtoChain(Atom name, ScriptObject* o, Traits *origObjTraits) const { // todo will delegate always be non-null here? if (o != NULL) { Atom searchname = name; Stringp s = core()->atomToString(name); AvmAssert(s->isInterned()); Atom ival = s->getIntAtom(); if (ival) { searchname = ival; } do { // ensure prototype is dynamic if (!o->vtable->traits->getHashtableOffset()) continue; Atom const value = o->getTable()->getNonEmpty(searchname); if (!InlineHashtable::isEmpty(value)) return value; } while ((o = o->delegate) != NULL); } // NOTE use default public since name is not used Multiname multiname(core()->getAnyPublicNamespace(), AvmCore::atomToString(name)); toplevel()->throwReferenceError(kReadSealedError, &multiname, origObjTraits); // unreached return undefinedAtom; }
// this = argv[0] (ignored) // arg1 = argv[1] // argN = argv[argc] Atom RegExpClass::construct(int argc, Atom* argv) { AvmCore* core = this->core(); Stringp pattern; Atom patternAtom = (argc>0) ? argv[1] : undefinedAtom; Atom optionsAtom = (argc>1) ? argv[2] : undefinedAtom; if (AvmCore::istype(patternAtom, traits()->itraits)) { // Pattern is a RegExp object if (optionsAtom != undefinedAtom) { // ECMA 15.10.4.1 says to throw an error if flags specified toplevel()->throwTypeError(kRegExpFlagsArgumentError); } // Return a clone of the RegExp object RegExpObject* regExpObject = (RegExpObject*)AvmCore::atomToScriptObject(patternAtom); return (new (core->GetGC(), ivtable()->getExtraSize()) RegExpObject(regExpObject))->atom(); } else { if (patternAtom != undefinedAtom) { pattern = core->string(argv[1]); } else { // cn: disable this, breaking ecma3 tests. was: todo look into this. it's what SpiderMonkey does. pattern = core->kEmptyString; //core->newConstantStringLatin1("(?:)"); } } Stringp options = NULL; if (optionsAtom != undefinedAtom) { options = core->string(optionsAtom); } RegExpObject* inst = new (core->GetGC(), ivtable()->getExtraSize()) RegExpObject(this, pattern, options); return inst->atom(); }
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)); }
/** 15.2.4.5 Object.prototype.hasOwnProperty (V) When the hasOwnProperty method is called with argument V, the following steps are taken: 1. Let O be this object. 2. Call ToString(V). 3. If O doesnt have a property with the name given by Result(2), return false. 4. Return true. NOTE Unlike [[HasProperty]] (section 8.6.2.4), this method does not consider objects in the prototype chain. */ bool ObjectClass::_hasOwnProperty(Atom thisAtom, Stringp name) { AvmCore* core = this->core(); name = name ? core->internString(name) : (Stringp)core->knull; Traitsp t = NULL; switch (atomKind(thisAtom)) { case kObjectType: { // ISSUE should this look in traits and dynamic vars, or just dynamic vars. ScriptObject* obj = AvmCore::atomToScriptObject(thisAtom); if (obj->hasStringProperty(name)) return true; t = obj->traits(); break; } case kNamespaceType: case kStringType: case kBooleanType: case kDoubleType: case kIntegerType: t = toplevel()->toTraits(thisAtom); break; default: return false; } return t->getTraitsBindings()->findBinding(name, core->publicNamespace) != BIND_NONE; }
Float4Class::Float4Class(VTable* cvtable) : ClassClosure(cvtable) { toplevel()->_float4Class = this; // prototype objects are always vanilla objects. createVanillaPrototype(); }
static int emit_anf(void) { AST* tree = NULL; Parser* ctx = parser_new(NULL, stdin); while(NULL != (tree = toplevel(ctx))) pprint_tree(stdout, normalize(tree), 0); return 0; }
ByteArrayObject::ByteArrayObject(VTable *ivtable, ScriptObject *delegate) : ScriptObject(ivtable, delegate), m_byteArray(toplevel()) { c.set(&m_byteArray, sizeof(ByteArrayFile)); }
// this = argv[0] (ignored) // arg1 = argv[1] // argN = argv[argc] Atom MethodClosure::construct(int /*argc*/, Atom* /*argv*/) { // can't invoke method closure as constructor: // m = o.m; // new m(); // error toplevel()->throwTypeError(kCannotCallMethodAsConstructor, core()->toErrorString(_call->method)); return undefinedAtom; }
// this = argv[0] (ignored) // arg1 = argv[1] // argN = argv[argc] Atom ScriptObject::call(int /*argc*/, Atom* /*argv*/) { // TypeError in ECMA to execute a non-function // NOTE use default public since name is not used Multiname name(core()->getAnyPublicNamespace(), core()->kvalue); toplevel()->throwTypeError(kCallOfNonFunctionError, core()->toErrorString(&name)); return undefinedAtom; }
Atom Stubs::do_abc_callpropnsx(MethodFrame* f, const Multiname* name, Atom ns, Atom index, int argc, Atom* args) { Multiname tempname; MethodEnv* e = env(f); initnamensx(e, name, ns, index, &tempname); return toplevel(f)->callproperty(args[0], &tempname, argc - 1, args, toVTable(e, args[0])); }
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])); }
Atom Stubs::do_abc_callproplexns(MethodFrame* f, const Multiname* name, Atom ns, int argc, Atom* args) { Multiname tempname; MethodEnv* e = env(f); initnamens(e, name, ns, &tempname); Atom base = getBase(args); return toplevel(f)->callproperty(base, name, argc - 1, args, toVTable(e, base)); }
void ProgramClass::write(Stringp s) { if( !s ) { toplevel()->throwArgumentError(kNullArgumentError, "string"); } core()->console << s; }
static LV2UI_Handle instantiate( void* const ui_toplevel, const LV2UI_Descriptor* descriptor, const char* plugin_uri, const char* bundle_path, LV2UI_Write_Function write_function, LV2UI_Controller controller, RobWidget** widget, const LV2_Feature* const* features) { SFSUI* ui = (SFSUI*) calloc(1,sizeof(SFSUI)); *widget = NULL; ui->map = NULL; if (!strcmp(plugin_uri, MTR_URI "stereoscope")) { ; } else if (!strcmp(plugin_uri, MTR_URI "stereoscope_gtk")) { ; } else { free(ui); return NULL; } for (int i = 0; features[i]; ++i) { if (!strcmp(features[i]->URI, LV2_URID_URI "#map")) { ui->map = (LV2_URID_Map*)features[i]->data; } } if (!ui->map) { fprintf(stderr, "meters.lv2 UI: Host does not support urid:map\n"); free(ui); return NULL; } map_xfer_uris(ui->map, &ui->uris); lv2_atom_forge_init(&ui->forge, ui->map); ui->write = write_function; ui->controller = controller; ui->rate = 48000; ui->disable_signals = false; ui->update_grid = false; ui->clear_persistence = false; ui->fft_bins = 512; ui->freq_band = NULL; ui->freq_bins = 0; ui->width = SS_SIZE + 2 * SS_BORDER; ui->height = SS_SIZE + 2 * SS_BORDER; pthread_mutex_init(&ui->fft_lock, NULL); *widget = toplevel(ui, ui_toplevel); reinitialize_fft(ui, ui->fft_bins); ui_enable(ui); return ui; }
ClassClosure* DomainObject::getClass(Stringp name) { AvmCore *core = this->core(); if (name == NULL) { toplevel()->throwArgumentError(kNullArgumentError, core->toErrorString("name")); } // Search for a dot from the end. int dot = name->lastIndexOf(core->cachedChars[(int)'.']); // If there is a '.', this is a fully-qualified // class name in a package. Must turn it into // a namespace-qualified multiname. Namespace* ns; Stringp className; if (dot >= 0) { Stringp uri = core->internString(name->substring(0, dot)); ns = core->internNamespace(core->newNamespace(uri)); className = core->internString(name->substring(dot+1, name->length())); } else { ns = core->publicNamespace; className = core->internString(name); } Multiname multiname(ns, className); // OOO: In the distribution, we search core->codeContext()->domainEnv rather than // our own domainEnv, which is surely a bug? ScriptObject *container = finddef(multiname, domainEnv); if (!container) { toplevel()->throwTypeError(kClassNotFoundError, core->toErrorString(&multiname)); } Atom atom = toplevel()->getproperty(container->atom(), &multiname, container->vtable); if (!AvmCore::istype(atom, core->traits.class_itraits)) { toplevel()->throwTypeError(kClassNotFoundError, core->toErrorString(&multiname)); } return (ClassClosure*)AvmCore::atomToScriptObject(atom); }
Stringp NumberClass::_convert(double n, int precision, int mode) { AvmCore* core = this->core(); if (mode == MathUtils::DTOSTR_PRECISION) { if (precision < 1 || precision > 21) { toplevel()->throwRangeError(kInvalidPrecisionError, core->toErrorString(precision), core->toErrorString(1), core->toErrorString(21)); } } else { if (precision < 0 || precision > 20) { toplevel()->throwRangeError(kInvalidPrecisionError, core->toErrorString(precision), core->toErrorString(0), core->toErrorString(20)); } } return MathUtils::convertDoubleToString(core, n, mode, precision); }