Skip to content
This repository
tree: 86f350597c
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 60 lines (55 sloc) 1.713 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
<?php

class Foo {
var $foo = 'bar';
var $true = true;
var $false = false;
var $bar = array(1,2,3,1.23456789);
var $ass = array("life" => 42, "foo" => "bar");
function __set($name, $value)
{
echo "I'm setter!\n";
var_dump($name, $value);
}
function __get($name)
{
echo "I'm getter!\n";
var_dump($name);
}
function __call($name, $args)
{
echo "I'm caller!\n";
var_dump($name, $args);
}
}

$a = new V8Js();
$obj = new Foo;
$a->arr = array("foobar" => $obj);

$JS = <<< 'EOF'
  var example = new Object;
  example.foo = function () {
    print("this is foo");
  }
  example.bar = function () {
    print("this is bar");
  }
  example.__noSuchMethod__ = function (id, args) {
    print("tried to handle unknown method " + id);
    if (args.length != 0)
      print("it had arguments: " + args);
  }
  example.foo(); // alerts "this is foo"
  example.bar(); // alerts "this is bar"
  example.grill(); // alerts "tried to handle unknown method grill"
  example.ding("dong"); // alerts "tried to handle unknown method ding"
EOF;

try {
  $a->executeString("var myarr = new Array(); myarr[0] = 'foo'; myarr[1] = 'bar'; var_dump(myarr); var_dump(new Date('September 8, 1975 09:00:00'))", "call_test1.js");
  $a->executeString("var_dump(PHP.arr.foobar.bar);", "call_test2.js");
  $a->executeString("var_dump(PHP.arr.foobar.bar[0]);", "call_test3.js");
  $a->executeString("var_dump(var_dump(PHP.arr));", "call_test4.js");
  $a->executeString("var patt1=/[^a-h]/g; var_dump(patt1);", "call_test5.js");
  $a->executeString("var_dump(Math.PI, Infinity, null, undefined);", "call_test6.js");
// $a->executeString($JS);
} catch (V8JsException $e) {
  echo $e->getMessage(), "\n";
}
Something went wrong with that request. Please try again.