/* static */ ArgumentsObject * ArgumentsObject::create(JSContext *cx, HandleScript script, HandleFunction callee, unsigned numActuals, CopyArgs ©) { RootedObject proto(cx, callee->global().getOrCreateObjectPrototype(cx)); if (!proto) return NULL; bool strict = callee->strict(); Class *clasp = strict ? &StrictArgumentsObjectClass : &NormalArgumentsObjectClass; RootedTypeObject type(cx, proto->getNewType(cx, clasp)); if (!type) return NULL; RootedShape shape(cx, EmptyShape::getInitialShape(cx, clasp, TaggedProto(proto), proto->getParent(), FINALIZE_KIND, BaseShape::INDEXED)); if (!shape) return NULL; unsigned numFormals = callee->nargs; unsigned numDeletedWords = NumWordsForBitArrayOfLength(numActuals); unsigned numArgs = Max(numActuals, numFormals); unsigned numBytes = offsetof(ArgumentsData, args) + numDeletedWords * sizeof(size_t) + numArgs * sizeof(Value); ArgumentsData *data = (ArgumentsData *)cx->malloc_(numBytes); if (!data) return NULL; data->numArgs = numArgs; data->callee.init(ObjectValue(*callee.get())); data->script = script; /* Copy [0, numArgs) into data->slots. */ HeapValue *dst = data->args, *dstEnd = data->args + numArgs; copy.copyArgs(cx, dst); data->deletedBits = reinterpret_cast<size_t *>(dstEnd); ClearAllBitArrayElements(data->deletedBits, numDeletedWords); RawObject obj = JSObject::create(cx, FINALIZE_KIND, GetInitialHeap(GenericObject, clasp), shape, type); if (!obj) { js_free(data); return NULL; } obj->initFixedSlot(INITIAL_LENGTH_SLOT, Int32Value(numActuals << PACKED_BITS_COUNT)); obj->initFixedSlot(DATA_SLOT, PrivateValue(data)); copy.maybeForwardToCallObject(obj, data); ArgumentsObject &argsobj = obj->asArguments(); JS_ASSERT(argsobj.initialLength() == numActuals); JS_ASSERT(!argsobj.hasOverriddenLength()); return &argsobj; }
js::UnwrapOneChecked(RawObject obj, bool stopAtOuter) { if (!obj->isWrapper() || JS_UNLIKELY(!!obj->getClass()->ext.innerObject && stopAtOuter)) { return obj; } Wrapper *handler = Wrapper::wrapperHandler(obj); return handler->isSafeToUnwrap() ? Wrapper::wrappedObject(obj) : NULL; }
/* NB: An error object's private must be set through this function. */ static void SetExnPrivate(RawObject exnObject, JSExnPrivate *priv) { JS_ASSERT(!exnObject->getPrivate()); JS_ASSERT(exnObject->isError()); if (JSErrorReport *report = priv->errorReport) { if (JSPrincipals *prin = report->originPrincipals) JS_HoldPrincipals(prin); } exnObject->setPrivate(priv); }
js::UnwrapOneChecked(RawObject obj) { // Checked unwraps should never unwrap outer windows. if (!obj->isWrapper() || JS_UNLIKELY(!!obj->getClass()->ext.innerObject)) { return obj; } Wrapper *handler = Wrapper::wrapperHandler(obj); return handler->isSafeToUnwrap() ? Wrapper::wrappedObject(obj) : NULL; }
void linkInputLabels() { GraphicLayer* layer = GraphicLayer::sharedLayer(); CCArray* children = layer->getChildren(); if(children != NULL) { for(int i = 0 ; i < children->count(); i++) { RawObject* child = (RawObject*)children->objectAtIndex(i); //Force actualization of content size and fontSize after everything is loaded because the nodeToWorldTransform is only right after if(isKindOfClass(child, InputLabel)) { InputLabel* input = (InputLabel*)child; child->getNode()->setContentSize(child->getNode()->getContentSize()); if(input->getOriginalInfos() != NULL) { ((ui::EditBox*)child->getNode())->setFontSize(input->getOriginalInfos()->getFontSize()); } } if((isKindOfClass(child, InputLabel)) && child->getEventInfos()->objectForKey("LinkTo") != NULL && isKindOfClass(child->getEventInfos()->objectForKey("LinkTo"), CCString)) { InputLabel* input = (InputLabel*)child; if(input->getLinkTo() == NULL) { CCString* linkTo = (CCString*)child->getEventInfos()->objectForKey("LinkTo"); CCArray* matchs = layer->allObjectsWithName(linkTo); for(long j = 0; j < matchs->count(); j++) { RawObject* match = (RawObject*)matchs->objectAtIndex(j); if(isKindOfClass(match, LabelTTF)) { input->setLinkTo((LabelTTF*)match); j = matchs->count(); } } } } else if((isKindOfClass(child, DropDownList)) && child->getEventInfos()->objectForKey("LinkTo") != NULL && isKindOfClass(child->getEventInfos()->objectForKey("LinkTo"), CCString)) { DropDownList* dropDownList = (DropDownList*)child; if(dropDownList->getLinkTo() == NULL) { CCString* linkTo = (CCString*)child->getEventInfos()->objectForKey("LinkTo"); CCArray* matchs = layer->allObjectsWithName(linkTo); for(long j = 0; j < matchs->count(); j++) { RawObject* match = (RawObject*)matchs->objectAtIndex(j); if(isKindOfClass(match, LabelTTF)) { dropDownList->setLinkTo((LabelTTF*)match); j = matchs->count(); } } } } } } }
void reorderZindex() { GraphicLayer* layer = GraphicLayer::sharedLayer(); CCArray* children = layer->getChildren(); if(children != NULL) { for(int i = 0 ; i < children->count(); i++) { RawObject* child = (RawObject*)children->objectAtIndex(i); if(child->getZOrder() != 0) { layer->reorderChild(child, child->getZOrder()); } } } }
JSErrorReport * js_ErrorFromException(jsval exn) { if (JSVAL_IS_PRIMITIVE(exn)) return NULL; RawObject obj = JSVAL_TO_OBJECT(exn); if (!obj->isError()) return NULL; JSExnPrivate *priv = GetExnPrivate(obj); if (!priv) return NULL; return priv->errorReport; }
Image* Scene::getButtonAtPosition(Vec2 position, bool state) { Image* target = NULL; CCArray* objects = GraphicLayer::sharedLayer()->allVisibleObjectsAtPosition(position); for(int i = 0; i < objects->count() && target == NULL; i++) { RawObject* obj = (RawObject*)objects->objectAtIndex(i); if(obj->isVisible() && obj->getEventActivated() && !obj->getEventName().empty() && obj->getEventName()[0] != '\0' && dynamic_cast<Image*>(obj) != NULL) { //If state = false, the object imagefile must finish by "-on" and and have an _OriginalImageFile char *end = strrchr(((Image*)obj)->getImageFile().c_str(), '-'); if(state || (end && strcmp(end, "-on") == 0 && obj->getEventInfos()->objectForKey("_OriginalImageFile") != NULL)) target = (Image*)obj; } } return target; }
static void resc_trace(JSTracer *trc, RawObject obj) { void *pdata = obj->getPrivate(); JS_ASSERT(pdata); RegExpStatics *res = static_cast<RegExpStatics *>(pdata); res->mark(trc); }
void ArgumentsObject::trace(JSTracer *trc, RawObject obj) { ArgumentsObject &argsobj = obj->asArguments(); ArgumentsData *data = argsobj.data(); MarkValue(trc, &data->callee, js_callee_str); MarkValueRange(trc, data->numArgs, data->args, js_arguments_str); MarkScriptUnbarriered(trc, &data->script, "script"); }
static void regexp_trace(JSTracer *trc, RawObject obj) { /* * We have to check both conditions, since: * 1. During TraceRuntime, isHeapBusy() is true * 2. When a write barrier executes, IS_GC_MARKING_TRACER is true. */ if (trc->runtime->isHeapBusy() && IS_GC_MARKING_TRACER(trc)) obj->setPrivate(NULL); }
void Object::printToFd(int fd) { RawObject *raw = unTag<RawObject>(); switch (getTag()) { case RawObject::kPairTag: dprintf(fd, "<Pair @%p>", raw); break; case RawObject::kSymbolTag: dprintf(fd, "<Symbol %s>", raw->as<const char *>()); break; case RawObject::kSingletonTag: if (this == newNil()) { dprintf(fd, "<Nil>"); } else { dprintf(fd, "<Unknown-singleton %p>", this); } break; case RawObject::kFixnumTag: dprintf(fd, "<Fixnum %ld>", fromFixnum()); break; case RawObject::kClosureTag: dprintf(fd, "<Closure "); raw->cloInfo()->funcName()->printToFd(fd); dprintf(fd, " @%p>", raw); break; case RawObject::kVectorTag: dprintf(fd, "<Vector %p>", raw); break; default: dprintf(fd, "<Unknown-ptr %p>", this); break; } }
bool JSCompartment::wrap(JSContext *cx, MutableHandleValue vp, HandleObject existingArg) { JS_ASSERT(cx->compartment == this); JS_ASSERT_IF(existingArg, existingArg->compartment() == cx->compartment); JS_ASSERT_IF(existingArg, vp.isObject()); JS_ASSERT_IF(existingArg, IsDeadProxyObject(existingArg)); unsigned flags = 0; JS_CHECK_CHROME_RECURSION(cx, return false); #ifdef DEBUG struct AutoDisableProxyCheck { JSRuntime *runtime; AutoDisableProxyCheck(JSRuntime *rt) : runtime(rt) { runtime->gcDisableStrictProxyCheckingCount++; } ~AutoDisableProxyCheck() { runtime->gcDisableStrictProxyCheckingCount--; } } adpc(rt); #endif /* Only GC things have to be wrapped or copied. */ if (!vp.isMarkable()) return true; if (vp.isString()) { RawString str = vp.toString(); /* If the string is already in this compartment, we are done. */ if (str->zone() == zone()) return true; /* If the string is an atom, we don't have to copy. */ if (str->isAtom()) { JS_ASSERT(str->zone() == cx->runtime->atomsCompartment->zone()); return true; } } /* * Wrappers should really be parented to the wrapped parent of the wrapped * object, but in that case a wrapped global object would have a NULL * parent without being a proper global object (JSCLASS_IS_GLOBAL). Instead, * we parent all wrappers to the global object in their home compartment. * This loses us some transparency, and is generally very cheesy. */ HandleObject global = cx->global(); /* Unwrap incoming objects. */ if (vp.isObject()) { RootedObject obj(cx, &vp.toObject()); if (obj->compartment() == this) return WrapForSameCompartment(cx, obj, vp); /* Translate StopIteration singleton. */ if (obj->isStopIteration()) return js_FindClassObject(cx, JSProto_StopIteration, vp); /* Unwrap the object, but don't unwrap outer windows. */ obj = UnwrapObject(obj, /* stopAtOuter = */ true, &flags); if (obj->compartment() == this) return WrapForSameCompartment(cx, obj, vp); if (cx->runtime->preWrapObjectCallback) { obj = cx->runtime->preWrapObjectCallback(cx, global, obj, flags); if (!obj) return false; } if (obj->compartment() == this) return WrapForSameCompartment(cx, obj, vp); vp.setObject(*obj); #ifdef DEBUG { JSObject *outer = GetOuterObject(cx, obj); JS_ASSERT(outer && outer == obj); } #endif } RootedValue key(cx, vp); /* If we already have a wrapper for this value, use it. */ if (WrapperMap::Ptr p = crossCompartmentWrappers.lookup(key)) { vp.set(p->value); if (vp.isObject()) { RawObject obj = &vp.toObject(); JS_ASSERT(obj->isCrossCompartmentWrapper()); JS_ASSERT(obj->getParent() == global); } return true; } if (vp.isString()) { Rooted<JSLinearString *> str(cx, vp.toString()->ensureLinear(cx)); if (!str) return false; UnrootedString wrapped = js_NewStringCopyN<CanGC>(cx, str->chars(), str->length()); if (!wrapped) return false; vp.setString(wrapped); if (!putWrapper(key, vp)) return false; if (str->zone()->isGCMarking()) { /* * All string wrappers are dropped when collection starts, but we * just created a new one. Mark the wrapped string to stop it being * finalized, because if it was then the pointer in this * compartment's wrapper map would be left dangling. */ JSString *tmp = str; MarkStringUnbarriered(&rt->gcMarker, &tmp, "wrapped string"); JS_ASSERT(tmp == str); } return true; } RootedObject proto(cx, Proxy::LazyProto); RootedObject obj(cx, &vp.toObject()); RootedObject existing(cx, existingArg); if (existing) { /* Is it possible to reuse |existing|? */ if (!existing->getTaggedProto().isLazy() || existing->getClass() != &ObjectProxyClass || existing->getParent() != global || obj->isCallable()) { existing = NULL; } } /* * We hand in the original wrapped object into the wrap hook to allow * the wrap hook to reason over what wrappers are currently applied * to the object. */ RootedObject wrapper(cx); wrapper = cx->runtime->wrapObjectCallback(cx, existing, obj, proto, global, flags); if (!wrapper) return false; // We maintain the invariant that the key in the cross-compartment wrapper // map is always directly wrapped by the value. JS_ASSERT(Wrapper::wrappedObject(wrapper) == &key.get().toObject()); vp.setObject(*wrapper); return putWrapper(key, vp); }
JS_GetObjectFunction(RawObject obj) { if (obj->isFunction()) return obj->toFunction(); return NULL; }
void Object::gcScavenge(ThreadState *ts) { switch (getTag()) { case RawObject::kPairTag: ts->gcScavenge(&raw()->car()); ts->gcScavenge(&raw()->cdr()); break; case RawObject::kSymbolTag: break; case RawObject::kSingletonTag: case RawObject::kFixnumTag: assert(0 && "Object::gcScavenge: not heap allocated"); case RawObject::kClosureTag: { RawObject *info = raw()->cloInfo(); if (!info) { // info is NULL? happens when a supercombinator // is just being compiled in the codegen. break; } Object **payload = raw()->cloPayload(); for (intptr_t i = 0; i < info->funcNumPayload(); ++i) { ts->gcScavenge(payload + i); } ts->gcScavenge(&info->funcName()); ts->gcScavenge(&info->funcConstOffset()); // Scavenge const ptrs in code // @See codegen2.cpp //Util::logObj("scavenge code", info->funcConstOffset()); intptr_t len = info->funcConstOffset()->raw()->vectorSize(); for (intptr_t i = 0; i < len; ++i) { intptr_t offset = info->funcConstOffset()-> raw()->vectorAt(i)->fromFixnum(); intptr_t ptrLoc = info->funcCodeAs<intptr_t>() + offset; //Object *oldPtrVal = *(Object **) ptrLoc; ts->gcScavenge(reinterpret_cast<Object **>(ptrLoc)); //dprintf(2, "[ScavCodeReloc] %s[%ld] (which is %p) %p => %p ", // info->funcName()->rawSymbol(), // offset, // (void *) ptrLoc, // *(Object **) ptrLoc, // oldPtrVal); //(*(Object **) ptrLoc)->displayDetail(2); //dprintf(2, "\n"); } // And instructs valgrind to discard out-of-date jitted codes // Must do this since we have changed our code VALGRIND_DISCARD_TRANSLATIONS( info->funcCodeAs<char *>(), info->funcCodeAs<char *>() + info->funcSize() - RawObject::kFuncCodeOffset); break; } case RawObject::kVectorTag: { Object **elems = &raw()->vectorElem(); for (intptr_t i = 0; i < raw()->vectorSize(); ++i) { ts->gcScavenge(elems + i); } break; } default: assert(0 && "Object::gcScavenge: not a tagged object"); } }
static void resc_finalize(FreeOp *fop, RawObject obj) { RegExpStatics *res = static_cast<RegExpStatics *>(obj->getPrivate()); fop->delete_(res); }
void Object::displayDetail(int fd) { RawObject *raw = unTag<RawObject>(); switch (getTag()) { case RawObject::kPairTag: dprintf(fd, "("); displayListDetail(fd); dprintf(fd, ")"); break; case RawObject::kSymbolTag: dprintf(fd, "%s", raw->as<const char *>()); break; case RawObject::kSingletonTag: if (this == newNil()) { dprintf(fd, "()"); } else if (this == newTrue()) { dprintf(fd, "#t"); } else if (this == newFalse()) { dprintf(fd, "#f"); } else if (this == newVoid()) { dprintf(fd, "<void>"); } else { dprintf(fd, "<Unknown-singleton %p>", this); } break; case RawObject::kFixnumTag: dprintf(fd, "%ld", fromFixnum()); break; case RawObject::kClosureTag: if (raw->cloInfo()) { dprintf(fd, "<Closure "); raw->cloInfo()->funcName()->displayDetail(fd); dprintf(fd, ">"); } else { // info table is null during compilation dprintf(fd, "<Semi-Closure %p>", raw); } break; case RawObject::kVectorTag: { dprintf(fd, "(#"); for (intptr_t i = 0, len = raw->vectorSize(); i < len; ++i) { dprintf(fd, " "); raw->vectorAt(i)->displayDetail(fd); } dprintf(fd, ")"); break; } default: dprintf(fd, "<Unknown-ptr %p>", this); break; } }
void loadNodeToFenneX(Node* baseNode, Panel* parent) { GraphicLayer* layer = GraphicLayer::sharedLayer(); if(parent == NULL) { layer->useBaseLayer((Layer*)baseNode); #if VERBOSE_LOAD_CCB CCLOG("replaced base layer by CCB node : position : %f, %f, scale : %f", baseNode->getPosition().x, baseNode->getPosition().y, baseNode->getScale()); #endif } //Use an index because InputLabel modify the array, so you need to rewind a bit at some point for(int i = 0; i < baseNode->getChildren().size(); i++) { Node* node = baseNode->getChildren().at(i); #if VERBOSE_LOAD_CCB CCLOG("doing child %d from parent %s ...", i, parent != NULL ? parent->getName() != "" ? parent->getName().c_str() : "Panel" : "base layer"); #endif RawObject* result = NULL; if(isKindOfClass(node, Label)) { Label* label = (Label*)node; #if VERBOSE_LOAD_CCB CCLOG("label, font : %s", label->getSystemFontName().c_str()); #endif CCString* translationKey = isKindOfClass(label, CustomBaseNode) ? (CCString*)dynamic_cast<CustomBaseNode*>(label)->getParameters()->objectForKey("translationKey") : NULL; const std::string translated = Localization::getLocalizedString(translationKey != NULL ? translationKey->getCString() : label->getString()); if(translationKey == NULL || translationKey->compare(translated.c_str()) != 0) { //Don't replace the string if it's the same, as it may only be a key, not a real label label->setString(translated); } result = layer->createLabelTTFromLabel(label, parent); } else if(isKindOfClass(node, CustomDropDownList)) { #if VERBOSE_LOAD_CCB CCLOG("DropDownList"); #endif Sprite* sprite = (Sprite*)node; result = layer->createDropDownListFromSprite(sprite, parent); } else if(isKindOfClass(node, Sprite)) { #if VERBOSE_LOAD_CCB CCLOG("image"); #endif Sprite* sprite = (Sprite*)node; result = layer->createImageFromSprite(sprite, parent); } else if(isKindOfClass(node, CustomInput)) { #if VERBOSE_LOAD_CCB CCLOG("input label"); #endif ui::Scale9Sprite* sprite = (ui::Scale9Sprite*)node; CCString* translationKey = isKindOfClass(sprite, CustomBaseNode) ? (CCString*)dynamic_cast<CustomBaseNode*>(sprite)->getParameters()->objectForKey("translationKey") : NULL; std::string placeHolder = isKindOfClass(sprite, CustomInput) ? ((CustomInput*) sprite)->getPlaceHolder()->getCString() : ""; result = layer->createInputLabelFromScale9Sprite(sprite, parent); const std::string text = Localization::getLocalizedString(translationKey != NULL ? translationKey->getCString() : placeHolder.c_str()); if(translationKey == NULL || translationKey->compare(text.c_str()) != 0) { ((InputLabel*) result)->setInitialText(text); } i--; } else if(isKindOfClass(node, ui::Scale9Sprite)) { #if VERBOSE_LOAD_CCB CCLOG("scale sprite"); #endif ui::Scale9Sprite* sprite = (ui::Scale9Sprite*)node; result = layer->createCustomObjectFromNode(sprite, parent); } else if(!isKindOfClass(node, ui::EditBox)) { #if VERBOSE_LOAD_CCB CCLOG("Edit Box"); #endif result = layer->createPanelFromNode(node, parent); } #if VERBOSE_LOAD_CCB if(result != NULL) { CCLOG("Child %d loaded : position : %f, %f, scale : %f", i, result->getPosition().x, result->getPosition().y, result->getScale()); } else { CCLOG("Problem loading child %d !", i); } #endif } }
bool js::IsCrossCompartmentWrapper(RawObject wrapper) { return wrapper->isWrapper() && !!(Wrapper::wrapperHandler(wrapper)->flags() & Wrapper::CROSS_COMPARTMENT); }
Blob::Blob(const RawObject &other) : RawObject(other) , d(RawObject::d) { Q_ASSERT(other.isBlob()); }
RawObject::RawObject(const RawObject &other) : QObject(other.parent()) , d(other.d) { }
void ArgumentsObject::finalize(FreeOp *fop, RawObject obj) { fop->free_(reinterpret_cast<void *>(obj->asArguments().data())); }
static void GlobalDebuggees_finalize(FreeOp *fop, RawObject obj) { fop->delete_((GlobalObject::DebuggerVector *) obj->getPrivate()); }
bool RawObject::operator==(const RawObject &other) const { return id() == other.id(); }