|
| 1 | +--TEST-- |
| 2 | +V8\FunctionTemplate::Set() |
| 3 | +--SKIPIF-- |
| 4 | +<?php if (!extension_loaded("v8")) { |
| 5 | + print "skip"; |
| 6 | +} ?> |
| 7 | +--FILE-- |
| 8 | +<?php |
| 9 | +/** @var \Phpv8Testsuite $helper */ |
| 10 | +$helper = require '.testsuite.php'; |
| 11 | + |
| 12 | +require '.v8-helpers.php'; |
| 13 | +$v8_helper = new PhpV8Helpers($helper); |
| 14 | + |
| 15 | + |
| 16 | +$isolate = new \V8\Isolate(); |
| 17 | +$context = new V8\Context($isolate); |
| 18 | +$v8_helper->injectConsoleLog($context); |
| 19 | + |
| 20 | +// Tests: |
| 21 | + |
| 22 | +$ft = new \V8\FunctionTemplate($isolate); |
| 23 | +$ft->SetClassName(new \V8\StringValue($isolate, 'Test')); |
| 24 | + |
| 25 | +$proto = $ft->PrototypeTemplate(); |
| 26 | + |
| 27 | +$f = new \V8\FunctionObject($context, function (\V8\FunctionCallbackInfo $args) { |
| 28 | +}); |
| 29 | + |
| 30 | +try { |
| 31 | + $proto->Set(new \V8\StringValue($isolate, 'foo'), $f); |
| 32 | +} catch (TypeError $e) { |
| 33 | + $helper->exception_export($e); |
| 34 | +} |
| 35 | + |
| 36 | +$ftpl2 = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $args) { |
| 37 | + var_dump($args->This(), $args->Holder(), $args->NewTarget()); |
| 38 | +}); |
| 39 | + |
| 40 | +$proto->Set(new \V8\StringValue($isolate, 'foo'), $ftpl2); |
| 41 | + |
| 42 | +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 't'), $ft->GetFunction($context)); |
| 43 | + |
| 44 | + |
| 45 | +$v8_helper->CompileRun($context, ' |
| 46 | +console.log(t); |
| 47 | +let nt = new t(); |
| 48 | +console.log(nt); |
| 49 | +console.log(nt.foo); |
| 50 | +'); |
| 51 | + |
| 52 | + |
| 53 | +?> |
| 54 | +--EXPECT-- |
| 55 | +TypeError: Argument 3 passed to V8\ObjectTemplate::Set() should be instance of \V8\PrimitiveValue or \V8\Template, instance of V8\FunctionObject given |
| 56 | +function Test() { [native code] } |
| 57 | +[object Test] |
| 58 | +function foo() { [native code] } |
0 commit comments