Exemplo n.º 1
0
	void Process::_GetEnvironment(const ValueList& args, KValueRef result)
	{
		if (args.size() > 0 && args.at(0)->IsString())
		{
			KValueRef value = environment->Get(args.at(0)->ToString());
			result->SetValue(value);
		}
		else {
			result->SetObject(environment);
		}
	}
Exemplo n.º 2
0
	void PHPEvaluator::Evaluate(const ValueList& args, KValueRef result)
	{
		static Poco::Mutex evaluatorMutex;
		Poco::Mutex::ScopedLock evaluatorLock(evaluatorMutex);

		args.VerifyException("evaluate", "s s s o");

		TSRMLS_FETCH();
		string mimeType(args.GetString(0));
		string name(args.GetString(1));
		string code(args.GetString(2));
		KObjectRef windowGlobal(args.GetObject(3));
		KValueRef kv(Value::Undefined);

		// Contexts must be the same for runs with the same global object.
		string contextId(GetContextId(windowGlobal));
		PHPUtils::GenerateCaseMap(code TSRMLS_CC);

		std::ostringstream codeString;
		codeString << "namespace " << contextId << " {\n";
		codeString << code << "\n";
		codeString << "  $__fns = get_defined_functions();\n";
		codeString << "  if (array_key_exists(\"user\", $__fns)) {\n";
		codeString << "   foreach($__fns[\"user\"] as $fname) {\n";
		codeString << "    if (!$window->$fname) {";
		codeString << "      krollAddFunction($window, $fname);\n";
		codeString << "    }\n";
		codeString << "   }\n";
		codeString << "  }\n";
		codeString << "}\n";
		printf("%s\n", codeString.str().c_str());

		// This seems to be needed to make PHP actually give us errors
		// at parse/compile time -- see: main/main.c line 969
		PG(during_request_startup) = 0;

		KObjectRef previousGlobal(PHPUtils::GetCurrentGlobalObject());
		PHPUtils::SwapGlobalObject(windowGlobal, &EG(symbol_table) TSRMLS_CC);

		zend_first_try
		{
			zend_eval_string((char *) codeString.str().c_str(), NULL, 
				(char *) name.c_str() TSRMLS_CC);
		}
		zend_catch
		{
			Logger::Get("PHP")->Error("Evaluation of script failed");
		}
		zend_end_try();

		PHPUtils::SwapGlobalObject(previousGlobal, &EG(symbol_table) TSRMLS_CC);
		result->SetValue(kv);
	}
Exemplo n.º 3
0
    void RubyEvaluator::Evaluate(const ValueList& args, KValueRef result)
    {
        args.VerifyException("evaluate", "s s s o");
        
        //const char *mimeType = args.GetString(0).c_str();
        std::string name = args.GetString(1);
        std::string code = args.GetString(2);
        global_object = args.GetObject(3);

        VALUE ctx = this->GetContext(global_object);

        VALUE rargs = rb_ary_new();
        rb_ary_push(rargs, ctx);
        rb_ary_push(rargs, rb_str_new2(code.c_str()));

        int error;
        VALUE returnValue = rb_protect(reval_do_call, rargs, &error);
        RubyEvaluator::ContextToGlobal(ctx, global_object);

        if (error != 0)
        {
            std::string error("An error occured while parsing Ruby (");
            error += name;
            error += "): ";

            // Display a stringified version of the exception.
            VALUE exception = rb_gv_get("$!");
            KValueRef v = RubyUtils::ToKrollValue(exception);
            SharedString ss = v->DisplayString();
            error.append(ss->c_str());

            // Try to make a nice backtrace for the user.
            VALUE backtrace = rb_funcall(exception,
                rb_intern("backtrace"), 0);
            VALUE rBacktraceString = rb_funcall(backtrace,
                rb_intern("join"), 1, rb_str_new2("\n"));
            if (TYPE(rBacktraceString) == T_STRING)
            {
                error.append("\n");
                error.append(StringValuePtr(rBacktraceString));
            }

            Logger *logger = Logger::Get("Ruby");
            logger->Error(error);

            result->SetUndefined();
            return;
        }

        result->SetValue(RubyUtils::ToKrollValue(returnValue));
    }
Exemplo n.º 4
0
    void APIBinding::_RunOnMainThread(const ValueList& args, KValueRef result)
    {
        if (!args.at(0)->IsMethod())
        {
            throw ValueException::FromString(
                "First argument to runOnMainThread was not a function");

        }
        else
        {
            ValueList outArgs;
            for (size_t i = 1; i < args.size(); i++)
                outArgs.push_back(args.at(i));

            result->SetValue(RunOnMainThread(args.GetMethod(0), outArgs));
        }
    }
Exemplo n.º 5
0
    void APIBinding::_Get(const ValueList& args, KValueRef result)
    {
        string s = args.at(0)->ToString();
        const char *key = s.c_str();
        KValueRef r = 0;
        string::size_type pos = s.find_first_of(".");

        if (pos==string::npos)
        {
            r = this->Get(key);
        }
        else
        {
            // if we have a period, make it relative to the
            // global scope such that <module>.<key> would resolve
            // to the 'module' with key named 'key'
            r = global->GetNS(key);
        }
        result->SetValue(r);
    }
Exemplo n.º 6
0
	void Process::_GetExitCode(const ValueList& args, KValueRef result)
	{
		result->SetValue(exitCode);
	}