1 | /* |
||
2 | Javascript Object ______ ________________ |
||
3 | Inheritance Implementation __ / / __ \/ _/ _/\_____ \ |
||
4 | / // / /_/ // /_/ / _(__ < |
||
5 | Copyright 2014, Harold Iedema. \___/\____/___/___/ / \ |
||
6 | --------------------------------------------------------------- /______ / --- |
||
7 | Permission is hereby granted, free of charge, to any person obtaining \/ |
||
8 | a copy of this software and associated documentation files (the |
||
9 | "Software"), to deal in the Software without restriction, including |
||
10 | without limitation the rights to use, copy, modify, merge, publish, |
||
11 | distribute, sublicense, and/or sell copies of the Software, and to |
||
12 | permit persons to whom the Software is furnished to do so, subject to |
||
13 | the following conditions: |
||
14 | |||
15 | The above copyright notice and this permission notice shall be |
||
16 | included in all copies or substantial portions of the Software. |
||
17 | |||
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||
19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||
20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||
21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
||
22 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
||
23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
||
24 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
25 | ------------------------------------------------------------------------------ |
||
26 | */ |
||
27 | |||
28 | /** |
||
29 | * TestSuite Definition |
||
30 | */ |
||
31 | var testsuite = { |
||
32 | code: |
||
33 | // For browser testing, you can either test the compiled version, or the source version, by toggling which is commented out |
||
34 | // In Node.js, only the compiled version works, so be sure to switch to that before testing there |
||
35 | /** / |
||
36 | "./dist/joii.js", |
||
37 | /**/ |
||
38 | [ |
||
39 | 'src/Compatibility.js', |
||
40 | 'src/PrototypeBuilder.js', |
||
41 | 'src/ClassBuilder.js', |
||
42 | 'src/InterfaceBuilder.js', |
||
43 | 'src/EnumBuilder.js', |
||
44 | 'src/Reflection.js', |
||
45 | 'src/Config.js', |
||
46 | 'src/joii.js' |
||
47 | ], |
||
48 | /**/ |
||
49 | tests: [ |
||
50 | // PrototypeBuilder |
||
51 | "./test/PrototypeBuilder/DeepCopyTest.js", |
||
52 | "./test/PrototypeBuilder/InheritanceTest.js", |
||
53 | "./test/PrototypeBuilder/PropertyMetaTest.js", |
||
54 | "./test/PrototypeBuilder/TraitTest.js", |
||
55 | // ClassBuilder |
||
56 | "./test/ClassBuilder/InstantiationTest.js", |
||
57 | "./test/ClassBuilder/InheritanceTest.js", |
||
58 | "./test/ClassBuilder/AbstractImplementationTest.js", |
||
59 | "./test/ClassBuilder/VisibilityTest.js", |
||
60 | "./test/ClassBuilder/GetterTest.js", |
||
61 | "./test/ClassBuilder/SetterValidationTest.js", |
||
62 | "./test/ClassBuilder/NullableTypeTest.js", |
||
63 | "./test/ClassBuilder/TypeValidationTest.js", |
||
64 | "./test/ClassBuilder/InstanceOfTest.js", |
||
65 | "./test/ClassBuilder/CallTest.js", |
||
66 | "./test/ClassBuilder/ConstantTest.js", |
||
67 | "./test/ClassBuilder/SerializeTest.js", |
||
68 | "./test/ClassBuilder/FunctionOverloadingTests.js", |
||
69 | // InterfaceBuilder, |
||
70 | "./test/InterfaceBuilder/InterfaceBuilderTest.js", |
||
71 | "./test/InterfaceBuilder/InterfaceValidationTest.js", |
||
72 | // EnumBuilder |
||
73 | "./test/EnumBuilder/EnumBuilderTest.js", |
||
74 | // Reflection |
||
75 | "./test/Reflection/ReflectionTest.js", |
||
76 | // GitHub Reported Issues |
||
77 | "./test/IssueReports/IssueReport4.js", |
||
78 | "./test/IssueReports/IssueReport9.js", |
||
79 | "./test/IssueReports/IssueReport10.js", |
||
80 | "./test/IssueReports/IssueReport11.js", |
||
81 | "./test/IssueReports/IssueReport15.js", |
||
82 | "./test/IssueReports/IssueReport16.js", |
||
83 | "./test/IssueReports/IssueReport19.js", |
||
84 | "./test/IssueReports/IssueReport21.js", |
||
85 | "./test/IssueReports/IssueReport25.js" |
||
86 | ] |
||
87 | }; |
||
88 | |||
89 | /** |
||
90 | * Platform-independent bootstrap. |
||
91 | */ |
||
92 | if (typeof(window) === 'undefined') { |
||
93 | // Are we running on CLI / NodeJS ? |
||
94 | var qunit = require("qunit"); |
||
95 | qunit.run(testsuite); |
||
96 | } else { |
||
97 | // We're running a browser. |
||
98 | // ensure that all scripts load in the right order, so that the tests have the same ordinal each time |
||
99 | var loaded_scripts = 0; |
||
100 | var total_scripts = testsuite.tests.length; |
||
101 | |||
102 | var all_scripts_to_load = []; |
||
103 | |||
104 | var array_index = 0; |
||
105 | |||
106 | if (typeof(testsuite.code) === 'object') { |
||
107 | total_scripts += testsuite.code.length; |
||
108 | all_scripts_to_load = testsuite.code.slice(0); |
||
109 | } |
||
110 | else { |
||
111 | total_scripts++; |
||
112 | all_scripts_to_load.push(testsuite.code); |
||
113 | } |
||
114 | |||
115 | Array.prototype.push.apply(all_scripts_to_load, testsuite.tests); |
||
116 | |||
117 | |||
118 | var loadNextScript = function(file) { |
||
119 | if (array_index < all_scripts_to_load.length) { |
||
0 ignored issues
–
show
|
|||
120 | addScript(all_scripts_to_load[array_index]); |
||
121 | array_index++; |
||
122 | } |
||
123 | }; |
||
124 | |||
125 | var addScript = function(file) { |
||
0 ignored issues
–
show
|
|||
126 | var s = document.createElement('script'); |
||
127 | s.setAttribute('type', 'text/javascript'); |
||
128 | s.setAttribute('src', file); |
||
129 | s.onload = function() { |
||
130 | loaded_scripts++; |
||
131 | loadNextScript(); |
||
132 | }; |
||
133 | document.getElementsByTagName('head')[0].appendChild(s); |
||
134 | }; |
||
135 | |||
136 | function require() { |
||
137 | return window; |
||
138 | } |
||
139 | |||
140 | loadNextScript(); |
||
141 | } |
||
142 |
Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.
Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.
We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.