This repository was archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathObjectTemplate.phpt
71 lines (52 loc) · 1.96 KB
/
ObjectTemplate.phpt
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
60
61
62
63
64
65
66
67
68
69
70
71
--TEST--
V8\ObjectTemplate
--SKIPIF--
<?php if (!extension_loaded("v8")) print "skip"; ?>
--FILE--
<?php
/** @var \Phpv8Testsuite $helper */
$helper = require '.testsuite.php';
require '.v8-helpers.php';
$v8_helper = new PhpV8Helpers($helper);
// Tests:
$isolate = new \V8\Isolate();
$value = new \V8\ObjectTemplate($isolate);
$helper->header('Object representation');
$helper->dump($value);
$helper->space();
$helper->assert('ObjectTemplate extends Template', $value instanceof \V8\Template);
$helper->assert('ObjectTemplate implements AdjustableExternalMemoryInterface', $value instanceof \V8\AdjustableExternalMemoryInterface);
$helper->line();
$helper->header('Accessors');
$helper->method_matches($value, 'getIsolate', $isolate);
$helper->line();
$callback = function() {
echo 'Should never be called', PHP_EOL;
};
$fnc = new \V8\FunctionTemplate($isolate, $callback);
$fnc->setClassName(new \V8\StringValue($isolate, 'TestConstructor'));
$context = new \V8\Context($isolate);
$value = new \V8\ObjectTemplate($isolate, $fnc);
$instance = $value->newInstance($context);
$helper->assert('ObjectTemplate instance has name from constructor', $instance->getConstructorName()->value() == 'TestConstructor');
$helper->line();
$helper->assert('Object template is not immutable prototype by default', $value->isImmutableProto(), false);
$value->setImmutableProto();
$helper->assert('Object template is now set to be immutable prototype', $value->isImmutableProto(), true);
?>
--EXPECT--
Object representation:
----------------------
object(V8\ObjectTemplate)#4 (1) {
["isolate":"V8\Template":private]=>
object(V8\Isolate)#3 (0) {
}
}
ObjectTemplate extends Template: ok
ObjectTemplate implements AdjustableExternalMemoryInterface: ok
Accessors:
----------
V8\ObjectTemplate::getIsolate() matches expected value
ObjectTemplate instance has name from constructor: ok
Object template is not immutable prototype by default: ok
Object template is now set to be immutable prototype: ok