blob: 07f0e3c45928593d799626543d501613bd61dd8b [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2008 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
Ben Murdochb8a8cc12014-11-26 15:28:44 +000028// Flags: --expose-debug-as debug --expose-gc --send-idle-notification
Emily Bernierd0a1eb72015-03-24 16:35:39 -040029// Flags: --allow-natives-syntax
30// Flags: --noharmony-shipping
31// Note: this test checks that that the number of scripts reported as native
32// by Debug.scripts() is the same as a number of core native scripts.
33// Native scripts that are added by --harmony-shipping are classified
34// as 'experimental', but are still returned by Debug.scripts(), so
35// we disable harmony-shipping for this test
Ben Murdochb8a8cc12014-11-26 15:28:44 +000036
Steve Blocka7e24c12009-10-30 11:49:00 +000037// Get the Debug object exposed from the debug context global object.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000038Debug = debug.Debug;
Steve Blocka7e24c12009-10-30 11:49:00 +000039
40Date();
41RegExp();
42
43// Count script types.
44var named_native_count = 0;
Ben Murdoch69a99ed2011-11-30 16:03:39 +000045var named_native_names = {};
Steve Blocka7e24c12009-10-30 11:49:00 +000046var extension_count = 0;
47var normal_count = 0;
48var scripts = Debug.scripts();
49for (i = 0; i < scripts.length; i++) {
50 if (scripts[i].type == Debug.ScriptType.Native) {
51 if (scripts[i].name) {
Ben Murdoch69a99ed2011-11-30 16:03:39 +000052 // TODO(1641): Remove check for equally named native scripts once the
53 // underlying issue is fixed.
54 if (!named_native_names[scripts[i].name]) {
55 named_native_names[scripts[i].name] = true;
56 named_native_count++;
57 }
Steve Blocka7e24c12009-10-30 11:49:00 +000058 }
59 } else if (scripts[i].type == Debug.ScriptType.Extension) {
60 extension_count++;
61 } else if (scripts[i].type == Debug.ScriptType.Normal) {
62 normal_count++;
63 } else {
64 assertUnreachable('Unexpected type ' + scripts[i].type);
65 }
66}
67
68// This has to be updated if the number of native scripts change.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040069assertEquals(%NativeScriptsCount(), named_native_count);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000070// Only the 'gc' extension is loaded.
71assertEquals(1, extension_count);
Steve Blocka7e24c12009-10-30 11:49:00 +000072// This script and mjsunit.js has been loaded. If using d8, d8 loads
73// a normal script during startup too.
74assertTrue(normal_count == 2 || normal_count == 3);
75
76// Test a builtins script.
77var math_script = Debug.findScript('native math.js');
78assertEquals('native math.js', math_script.name);
79assertEquals(Debug.ScriptType.Native, math_script.type);
80
81// Test a builtins delay loaded script.
82var date_delay_script = Debug.findScript('native date.js');
83assertEquals('native date.js', date_delay_script.name);
84assertEquals(Debug.ScriptType.Native, date_delay_script.type);
85
86// Test a debugger script.
87var debug_delay_script = Debug.findScript('native debug.js');
88assertEquals('native debug.js', debug_delay_script.name);
89assertEquals(Debug.ScriptType.Native, debug_delay_script.type);
90
91// Test an extension script.
92var extension_gc_script = Debug.findScript('v8/gc');
93if (extension_gc_script) {
94 assertEquals('v8/gc', extension_gc_script.name);
95 assertEquals(Debug.ScriptType.Extension, extension_gc_script.type);
96}
97
98// Test a normal script.
99var mjsunit_js_script = Debug.findScript(/mjsunit.js/);
100assertTrue(/mjsunit.js/.test(mjsunit_js_script.name));
101assertEquals(Debug.ScriptType.Normal, mjsunit_js_script.type);
102
103// Check a nonexistent script.
104var dummy_script = Debug.findScript('dummy.js');
105assertTrue(typeof dummy_script == 'undefined');