Beispiel #1
0
int init_closure(ActRec* ar, TypedValue* sp) {
  auto closure = c_Closure::fromObject(ar->getThis());

  // Swap in the $this or late bound class or null if it is ony from a plain
  // function or pseudomain
  ar->setThisOrClassAllowNull(closure->getThisOrClass());

  if (ar->hasThis()) {
    ar->getThis()->incRefCount();
  }

  // Put in the correct context
  ar->m_func = closure->getInvokeFunc();

  // The closure is the first local.
  // Similar to tvWriteObject() but we don't incref because it used to be $this
  // and now it is a local, so they cancel out
  TypedValue* firstLocal = --sp;
  firstLocal->m_type = KindOfObject;
  firstLocal->m_data.pobj = closure;

  // Copy in all the use vars
  TypedValue* prop = closure->getUseVars();
  int n = closure->getNumUseVars();
  for (int i=0; i < n; i++) {
    tvDup(*prop++, *--sp);
  }

  return n + 1;
}
c_Continuation *c_Continuation::Clone(ObjectData* obj) {
  auto thiz = static_cast<c_Continuation*>(obj);
  auto fp = thiz->actRec();

  c_Continuation* cont = static_cast<c_Continuation*>(fp->getThisOrClass()
    ? CreateMeth(fp->func(), fp->getThisOrClass(), thiz->m_offset)
    : CreateFunc(fp->func(), thiz->m_offset));

  cont->copyContinuationVars(fp);

  cont->o_subclassData.u16 = thiz->o_subclassData.u16;
  cont->m_index  = thiz->m_index;
  cellSet(thiz->m_key, cont->m_key);
  cellSet(thiz->m_value, cont->m_value);

  return cont;
}