bool SetVariableCommand::executeImpl( DebuggerSession* session, folly::dynamic* responseMsg ) { folly::dynamic body = folly::dynamic::object; folly::dynamic variables = folly::dynamic::array; auto& args = tryGetObject(getMessage(), "arguments", s_emptyArgs); ServerObject* obj = session->getServerObject(m_objectId); if (obj == nullptr) { throw DebuggerCommandException("Invalid variablesReference specified."); } const std::string& suppliedName = tryGetString(args, "name", ""); if (suppliedName.empty()) { throw DebuggerCommandException("Invalid variable name specified."); } // Remove any prefixes that we would have added to the variable name // before presenting it to the front-end. std::string name = removeVariableNamePrefix(suppliedName); bool success = false; const std::string& strValue = tryGetString(args, "value", ""); try { if (obj->objectType() == ServerObjectType::Scope) { ScopeObject* scope = static_cast<ScopeObject*>(obj); switch (scope->m_scopeType) { case ScopeType::Locals: success = setLocalVariable( session, name, strValue, scope, &body ); break; case ScopeType::ServerConstants: success = setConstant( session, name, strValue, scope, &body ); break; // Superglobals and core constants are provided by the current execution // context, rather than trying to overwrite them here, defer to the PHP // console, which will let the runtime enforce whatever policies are // appropriate. case ScopeType::Superglobals: m_debugger->sendUserMessage( "Could not directly set value of superglobal variable, you may " "be able to set this value by running a Hack/PHP command in the " " console.", DebugTransport::OutputLevelError ); break; default: assertx(false); } } else if (obj->objectType() == ServerObjectType::Variable) { VariableObject* variable = static_cast<VariableObject*>(obj); Variant& variant = variable->m_variable; if (variant.isArray()) { success = setArrayVariable(session, name, strValue, variable, &body); } else if (variant.isObject()) { success = setObjectVariable(session, name, strValue, variable, &body); } else { throw DebuggerCommandException( "Failed to set variable: Unexpected variable type." ); } } } catch (DebuggerCommandException e) { m_debugger->sendUserMessage( e.what(), DebugTransport::OutputLevelError ); throw e; } if (!success) { throw DebuggerCommandException( "Failed to set variable." ); } (*responseMsg)["body"] = body; return false; }
Variable blendExpression::evaluate() { ImageObject* bottom = store->getImage(); Variable topVar = arguments[0]->getResult(); ImageObject* top = topVar.get<ImageObject>(); setLocalVariable("x", &x); setLocalVariable("y", &y); setLocalVariable("r1", &r1); setLocalVariable("g1", &g1); setLocalVariable("b1", &b1); setLocalVariable("h1", &h1); setLocalVariable("s1", &s1); setLocalVariable("v1", &v1); setLocalVariable("a1", &a1); setLocalVariable("r2", &r2); setLocalVariable("g2", &g2); setLocalVariable("b2", &b2); setLocalVariable("h2", &h2); setLocalVariable("s2", &s2); setLocalVariable("v2", &v2); setLocalVariable("a2", &a2); for (int cx = 0; cx < std::min(top->getWidth(),bottom->getWidth()); cx++) for (int cy = 0; cy < std::min(top->getHeight(), bottom->getHeight()); cy++) { x = cx; y = cy; if (store->mask->getValue(cx, cy) > 0) { Colour b = bottom->getPixel(cx, cy); r1 = (float)b.r(); g1 = (float)b.g(); b1 = (float)b.b(); h1 = (float)b.h(); s1 = (float)b.s(); v1 = (float)b.v(); a1 = (float)b.a(); Colour t = top->getPixel(cx, cy); r2 = (float)t.r(); g2 = (float)t.g(); b2 = (float)t.b(); h2 = (float)t.h(); s2 = (float)t.s(); v2 = (float)t.v(); a2 = (float)t.a(); Variable col = arguments[1]->getResult(); buffer->setPixel(cx, cy, *col.get<Colour>()); } } commitBuffer(); return Variable(); }