v8::Handle<v8::Value> JSSystemStruct::httpGet(const Transfer::URL& url, v8::Persistent<v8::Function> cb) { //first checks whether have capability to issue http request if(! checkCurCtxtHasCapability(NULL,Capabilities::HTTP)) V8_EXCEPTION_CSTR("Error: you do not have the capability to issue an http commad."); return associatedContext->httpGet(url, cb); }
v8::Handle<v8::Value> JSSystemStruct::sendMessageNoErrorHandler(JSPresenceStruct* jspres, const String& serialized_message,JSPositionListener* jspl,bool reliable) { if (! checkCurCtxtHasCapability(jspres, Capabilities::SEND_MESSAGE)) V8_EXCEPTION_CSTR("Error. You do not have the capability to send messages."); return associatedContext->sendMessageNoErrorHandler(jspres,serialized_message,jspl,reliable); }
//creates and returns a new context object. arguments should be described in //JSObjects/JSSystem.cpp //new context will have at most as many permissions as parent context. //note: if presStruct is null, just means use the one that is associated with //this system's context v8::Handle<v8::Value> JSSystemStruct::struct_createContext(JSPresenceStruct* jspres,const SpaceObjectReference& canSendTo, Capabilities::CapNum permNum) { //first checks whether have capability to create a context. if(! checkCurCtxtHasCapability(NULL,Capabilities::CREATE_SANDBOX)) V8_EXCEPTION_CSTR("Error: you do not have the capability to create a sandbox"); //prevents scripter from escalating capabilities beyond those that he/she //already has stripCapEscalation(permNum,Capabilities::SEND_MESSAGE,jspres,"SEND_MESSAGE"); stripCapEscalation(permNum,Capabilities::RECEIVE_MESSAGE,jspres,"RECEIVE_MESSAGE"); stripCapEscalation(permNum,Capabilities::IMPORT,jspres,"IMPORT"); stripCapEscalation(permNum,Capabilities::CREATE_PRESENCE,jspres,"CREATE_PRESENCE"); stripCapEscalation(permNum,Capabilities::CREATE_ENTITY,jspres,"CREATE_ENTITY"); stripCapEscalation(permNum,Capabilities::EVAL,jspres,"EVAL"); stripCapEscalation(permNum,Capabilities::PROX_CALLBACKS,jspres,"PROX_CALLBACKS"); stripCapEscalation(permNum,Capabilities::PROX_QUERIES,jspres,"PROX_QUERIES"); stripCapEscalation(permNum,Capabilities::CREATE_SANDBOX,jspres,"CREATE_SANDBOX"); stripCapEscalation(permNum,Capabilities::GUI,jspres,"GUI"); stripCapEscalation(permNum,Capabilities::HTTP,jspres,"HTTP"); stripCapEscalation(permNum,Capabilities::MOVEMENT,jspres,"MOVEMENT"); stripCapEscalation(permNum,Capabilities::MESH, jspres,"MESH"); return associatedContext->struct_createContext(jspres,canSendTo,permNum); }
v8::Handle<v8::Value> JSSystemStruct::httpRequest(Sirikata::Network::Address addr, Transfer::HttpManager::HTTP_METHOD method, String request, v8::Persistent<v8::Function> cb) { //first checks whether have capability to issue http request if(! checkCurCtxtHasCapability(NULL,Capabilities::HTTP)) V8_EXCEPTION_CSTR("Error: you do not have the capability to issue an http commad."); return associatedContext->httpRequest(addr,method,request,cb); }
v8::Handle<v8::Value> invoke(const v8::Arguments& args) { /* Decode the args array and send the call to the internal object */ EmersonScript* caller; JSInvokableObjectInt* invokableObj; bool decoded = decodeJSInvokableObject(args.This(), caller, invokableObj); if (! decoded) V8_EXCEPTION_CSTR("Could not decode invokable js object"); if (! invokableObj) V8_EXCEPTION_CSTR("Null field in invokable object"); /* create a vector of boost::any params here For now just take the first param and see that FIXME */ std::vector<boost::any> params; HandleScope scope; //assert(args.Length() == 1); for(int i =0; i < args.Length(); i++) params.push_back(InvokableUtil::V8ToAny(caller, args[i])); /* This is just a trampoline pattern */ boost::any b = invokableObj->invoke(params); if(b.empty()) { return v8::Undefined(); } Handle<Value> retval = InvokableUtil::AnyToV8(caller, b); return retval; }