@@ -71,219 +71,12 @@ $cache_data = null;
7171 $ source = new \V8 \ScriptCompiler \Source ($ source_string );
7272 $ helper ->assert ('Source cache data is not set ' , $ source ->getCachedData () === null );
7373 try {
74- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_CONSUME_PARSER_CACHE );
74+ $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_CONSUME_CODE_CACHE );
7575 } catch (\V8 \Exceptions \Exception $ e ) {
7676 $ helper ->exception_export ($ e );
7777 }
7878}
7979
80- {
81- $ helper ->header ('Test generating code cache ' );
82- $ source_string = new V8 \StringValue ($ isolate , '"test " + status ' );
83- $ source = new \V8 \ScriptCompiler \Source ($ source_string );
84- $ helper ->assert ('Source cache data is NULL ' , $ source ->getCachedData () === null );
85- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_PRODUCE_CODE_CACHE );
86- $ helper ->assert ('Source cache data is update ' , $ source ->getCachedData () != null );
87- $ helper ->assert ('Source cache data is not rejected ' , $ source ->getCachedData ()->isRejected () === false );
88-
89- $ cache_data = $ source ->getCachedData ();
90- $ helper ->line ();
91- }
92-
93- {
94- $ helper ->header ('Test consuming code cache ' );
95-
96- $ source = new \V8 \ScriptCompiler \Source ($ source_string , null , $ cache_data );
97- $ helper ->assert ('Source cache data is set ' , $ source ->getCachedData () != null );
98- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_CONSUME_CODE_CACHE );
99- $ helper ->assert ('Source cache data is still set ' , $ source ->getCachedData () != null );
100- $ helper ->assert ('Source cache data is not rejected ' , $ source ->getCachedData ()->isRejected () === false );
101-
102- $ helper ->line ();
103- }
104-
105- {
106- $ helper ->header ('Test generating full code cache ' );
107- $ source_string = new V8 \StringValue ($ isolate , '"test " + status ' );
108- $ source = new \V8 \ScriptCompiler \Source ($ source_string );
109- $ helper ->assert ('Source cache data is NULL ' , $ source ->getCachedData () === null );
110- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_PRODUCE_FULL_CODE_CACHE );
111- $ helper ->assert ('Source cache data is update ' , $ source ->getCachedData () != null );
112- $ helper ->assert ('Source cache data is not rejected ' , $ source ->getCachedData ()->isRejected () === false );
113-
114- $ cache_data = $ source ->getCachedData ();
115- $ helper ->line ();
116- }
117-
118- {
119- $ helper ->header ('Test consuming full code cache ' );
120-
121- $ source = new \V8 \ScriptCompiler \Source ($ source_string , null , $ cache_data );
122- $ helper ->assert ('Source cache data is set ' , $ source ->getCachedData () != null );
123- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_CONSUME_CODE_CACHE );
124- $ helper ->assert ('Source cache data is still set ' , $ source ->getCachedData () != null );
125- $ helper ->assert ('Source cache data is not rejected ' , $ source ->getCachedData ()->isRejected () === false );
126-
127- $ helper ->line ();
128- }
129-
130- {
131- $ helper ->header ('Test consuming code cache for wrong source ' );
132- $ source_string = new V8 \StringValue ($ isolate , '"other " + status ' );
133- $ source = new \V8 \ScriptCompiler \Source ($ source_string , null , $ cache_data );
134- $ helper ->assert ('Source cache data is set ' , $ source ->getCachedData () != null );
135- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_CONSUME_CODE_CACHE );
136- $ helper ->assert ('Source cache data is still set ' , $ source ->getCachedData () != null );
137- $ helper ->assert ('Source cache data is rejected ' , $ source ->getCachedData ()->isRejected () === true );
138-
139- $ helper ->line ();
140- }
141-
142- {
143- $ helper ->header ('Test consuming code cache for source with different formatting ' );
144- $ source_string = new V8 \StringValue ($ isolate , ' "test " + status ' );
145- $ source = new \V8 \ScriptCompiler \Source ($ source_string , null , $ cache_data );
146- $ helper ->assert ('Source cache data is set ' , $ source ->getCachedData () != null );
147- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_CONSUME_CODE_CACHE );
148- $ helper ->assert ('Source cache data is still set ' , $ source ->getCachedData () != null );
149- $ helper ->assert ('Source cache data is not rejected ' , $ source ->getCachedData ()->isRejected () !== false );
150-
151- $ helper ->line ();
152- }
153-
154- {
155- $ helper ->header ('Test generating code cache when it already set ' );
156- $ source_string = new V8 \StringValue ($ isolate , '"test " + status ' );
157- $ source = new \V8 \ScriptCompiler \Source ($ source_string , null , $ cache_data );
158- $ helper ->assert ('Source cache data is set ' , $ source ->getCachedData () != null );
159- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_PRODUCE_CODE_CACHE );
160- $ helper ->assert ('Source cache data is still set ' , $ source ->getCachedData () != null );
161- $ helper ->assert ('Source cache data is rejected ' , $ source ->getCachedData ()->isRejected () === true );
162-
163- $ helper ->line ();
164- }
165-
166- {
167- $ helper ->header ('Test consuming code cache when requesting parser cache ' );
168-
169- $ source_string = new V8 \StringValue ($ isolate , '"test " + status ' );
170- $ source = new \V8 \ScriptCompiler \Source ($ source_string , null , $ cache_data );
171- $ helper ->assert ('Source cache data is set ' , $ source ->getCachedData () != null );
172- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_CONSUME_PARSER_CACHE );
173- $ helper ->assert ('Source cache data is still set ' , $ source ->getCachedData () != null );
174- $ helper ->assert ('Source cache data is not rejected ' , $ source ->getCachedData ()->isRejected () !== true );
175-
176- $ helper ->line ();
177- }
178-
179- {
180- $ helper ->header ('Test parser cache generated not for for all code ' );
181-
182- $ source_string = new V8 \StringValue ($ isolate , '"test " + status ' );
183- $ source = new \V8 \ScriptCompiler \Source ($ source_string );
184- $ helper ->assert ('Source cache data is NULL ' , $ source ->getCachedData () === null );
185- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_PRODUCE_PARSER_CACHE );
186- $ helper ->assert ('Source cache data is NOT updated ' , $ source ->getCachedData () === null );
187-
188- $ helper ->line ();
189- }
190-
191- $ parser_cache_src = 'function test(arg1, args) {
192- if (arg1 > arg2) {
193- return 1+1;
194- } else {
195- return arg1 + arg2;
196- }
197- } ' ;
198-
199- {
200- $ helper ->header ('Test generating parser cache ' );
201-
202- $ source_string = new V8 \StringValue ($ isolate , $ parser_cache_src );
203- $ source = new \V8 \ScriptCompiler \Source ($ source_string );
204- $ helper ->assert ('Source cache data is NULL ' , $ source ->getCachedData () === null );
205- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_PRODUCE_PARSER_CACHE );
206- $ helper ->assert ('Source cache data is update ' , $ source ->getCachedData () != null );
207- $ helper ->assert ('Source cache data is not rejected ' , $ source ->getCachedData ()->isRejected () === false );
208-
209- $ cache_data = $ source ->getCachedData ();
210-
211- //$helper->dump($cache_data->getData());
212- $ helper ->line ();
213- }
214-
215- {
216- $ helper ->header ('Test consuming parser cache ' );
217-
218- $ source_string = new V8 \StringValue ($ isolate , $ parser_cache_src );
219- $ source = new \V8 \ScriptCompiler \Source ($ source_string , null , $ cache_data );
220- $ helper ->assert ('Source cache data is set ' , $ source ->getCachedData () != null );
221- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_CONSUME_PARSER_CACHE );
222- $ helper ->assert ('Source cache data is still set ' , $ source ->getCachedData () != null );
223- $ helper ->assert ('Source cache data is not rejected ' , $ source ->getCachedData ()->isRejected () === false );
224-
225- $ helper ->line ();
226- }
227-
228- {
229- $ helper ->header ('Test consuming parser cache on different source (function with the same name) ' );
230-
231- $ bin = $ cache_data ->getData ();
232- $ source_string = new V8 \StringValue ($ isolate , 'function test() { return 1+1;} ' );
233- $ source = new \V8 \ScriptCompiler \Source ($ source_string , null , $ cache_data );
234- $ helper ->assert ('Source cache data is set ' , $ source ->getCachedData () != null );
235- try {
236- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_CONSUME_PARSER_CACHE );
237- } catch (\V8 \Exceptions \TryCatchException $ e ) {
238- $ helper ->exception_export ($ e );
239- }
240-
241- $ helper ->line ();
242- }
243-
244- {
245- $ helper ->header ('Test consuming parser cache on different source ' );
246-
247- $ bin = $ cache_data ->getData ();
248- $ source_string = new V8 \StringValue ($ isolate , 'function test2() { return 1+1;} ' );
249- $ source = new \V8 \ScriptCompiler \Source ($ source_string , null , $ cache_data );
250- $ helper ->assert ('Source cache data is set ' , $ source ->getCachedData () != null );
251- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_CONSUME_PARSER_CACHE );
252- $ helper ->assert ('Source cache data is still set ' , $ source ->getCachedData () != null );
253- $ helper ->assert ('Source cache data is rejected ' , $ source ->getCachedData ()->isRejected () === true );
254- $ helper ->assert ('Source cache data is not changed ' , $ source ->getCachedData ()->getData () === $ bin );
255-
256- $ helper ->line ();
257- }
258-
259- {
260- $ helper ->header ('Test consuming parser cache on the same source with different formatting ' );
261-
262- $ source_string = new V8 \StringValue ($ isolate , ' ' . $ parser_cache_src );
263- $ source = new \V8 \ScriptCompiler \Source ($ source_string , null , $ cache_data );
264- $ helper ->assert ('Source cache data is set ' , $ source ->getCachedData () != null );
265- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_CONSUME_PARSER_CACHE );
266- $ helper ->assert ('Source cache data is still set ' , $ source ->getCachedData () != null );
267- $ helper ->assert ('Source cache data is rejected ' , $ source ->getCachedData ()->isRejected () === true );
268-
269- $ helper ->line ();
270- }
271-
272- {
273- $ helper ->header ('Test consuming code cache when parser cache given ' );
274-
275- $ source_string = new V8 \StringValue ($ isolate , $ parser_cache_src );
276- $ source = new \V8 \ScriptCompiler \Source ($ source_string , null , $ cache_data );
277- $ helper ->assert ('Source cache data is set ' , $ source ->getCachedData () != null );
278- $ script = V8 \ScriptCompiler::compile ($ context , $ source , V8 \ScriptCompiler::OPTION_CONSUME_CODE_CACHE );
279- $ helper ->assert ('Source cache data is still set ' , $ source ->getCachedData () != null );
280- $ helper ->assert ('Source cache data is not rejected ' , $ source ->getCachedData ()->isRejected () === false );
281-
282- $ helper ->line ();
283- }
284-
285-
286-
28780?>
28881--EXPECT--
28982Compiling:
@@ -303,91 +96,3 @@ Test cache when no cache set:
30396-----------------------------
30497Source cache data is not set: ok
30598V8\Exceptions\Exception: Unable to consume cache when it's not set
306- Test generating code cache:
307- ---------------------------
308- Source cache data is NULL: ok
309- Source cache data is update: ok
310- Source cache data is not rejected: ok
311-
312- Test consuming code cache:
313- --------------------------
314- Source cache data is set: ok
315- Source cache data is still set: ok
316- Source cache data is not rejected: ok
317-
318- Test generating full code cache:
319- --------------------------------
320- Source cache data is NULL: ok
321- Source cache data is update: ok
322- Source cache data is not rejected: ok
323-
324- Test consuming full code cache:
325- -------------------------------
326- Source cache data is set: ok
327- Source cache data is still set: ok
328- Source cache data is not rejected: ok
329-
330- Test consuming code cache for wrong source:
331- -------------------------------------------
332- Source cache data is set: ok
333- Source cache data is still set: ok
334- Source cache data is rejected: ok
335-
336- Test consuming code cache for source with different formatting:
337- ---------------------------------------------------------------
338- Source cache data is set: ok
339- Source cache data is still set: ok
340- Source cache data is not rejected: ok
341-
342- Test generating code cache when it already set:
343- -----------------------------------------------
344- Source cache data is set: ok
345- Source cache data is still set: ok
346- Source cache data is rejected: ok
347-
348- Test consuming code cache when requesting parser cache:
349- -------------------------------------------------------
350- Source cache data is set: ok
351- Source cache data is still set: ok
352- Source cache data is not rejected: ok
353-
354- Test parser cache generated not for for all code:
355- -------------------------------------------------
356- Source cache data is NULL: ok
357- Source cache data is NOT updated: ok
358-
359- Test generating parser cache:
360- -----------------------------
361- Source cache data is NULL: ok
362- Source cache data is update: ok
363- Source cache data is not rejected: ok
364-
365- Test consuming parser cache:
366- ----------------------------
367- Source cache data is set: ok
368- Source cache data is still set: ok
369- Source cache data is not rejected: ok
370-
371- Test consuming parser cache on different source (function with the same name):
372- ------------------------------------------------------------------------------
373- Source cache data is set: ok
374- V8\Exceptions\TryCatchException: SyntaxError: Unexpected end of input
375-
376- Test consuming parser cache on different source:
377- ------------------------------------------------
378- Source cache data is set: ok
379- Source cache data is still set: ok
380- Source cache data is rejected: ok
381- Source cache data is not changed: ok
382-
383- Test consuming parser cache on the same source with different formatting:
384- -------------------------------------------------------------------------
385- Source cache data is set: ok
386- Source cache data is still set: ok
387- Source cache data is rejected: ok
388-
389- Test consuming code cache when parser cache given:
390- --------------------------------------------------
391- Source cache data is set: ok
392- Source cache data is still set: ok
393- Source cache data is not rejected: ok
0 commit comments