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 pathContext.phpt
49 lines (34 loc) · 1.79 KB
/
Context.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
--TEST--
V8\Context
--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);
$isolate = new \V8\Isolate();
$context = new \V8\Context($isolate);
$helper->method_matches_instanceof($context, 'globalObject', \V8\ObjectValue::class);
$global = $context->globalObject();
$v8_helper->CHECK($global->sameValue($context->globalObject()), '$global->sameValue($context->globalObject())');
$helper->method_matches($context, 'isCodeGenerationFromStringsAllowed', true);
$v8_helper->CompileTryRun($context, 'eval("1+1")');
$helper->assert('Code generation allowed', $context->isCodeGenerationFromStringsAllowed() === true);
$context->allowCodeGenerationFromStrings(false);
$helper->assert('Code generation is not allowed', $context->isCodeGenerationFromStringsAllowed() === false);
$helper->method_matches_with_output($context, 'isCodeGenerationFromStringsAllowed', false);
$res = $v8_helper->CompileTryRun($context, 'eval("1+1")');
$context->setErrorMessageForCodeGenerationFromStrings(new \V8\StringValue($isolate, 'Whoa! Nope. No eval this time, sorry.'));
$res = $v8_helper->CompileTryRun($context, 'eval("2+2")');
?>
--EXPECT--
V8\Context::globalObject() result is instance of V8\ObjectValue
CHECK $global->sameValue($context->globalObject()): OK
V8\Context::isCodeGenerationFromStringsAllowed() matches expected value
Code generation allowed: ok
Code generation is not allowed: ok
V8\Context::isCodeGenerationFromStringsAllowed() matches expected false
eval("1+1"): V8\Exceptions\TryCatchException: EvalError: Code generation from strings disallowed for this context
eval("2+2"): V8\Exceptions\TryCatchException: EvalError: Whoa! Nope. No eval this time, sorry.