Note failure to use "use strict"; in JS

Add it automatically in enforcing mode.
This commit is contained in:
cim 2014-09-07 17:43:23 +01:00
parent 3b717304e8
commit cd32820a5f
3 changed files with 24 additions and 2 deletions

View File

@ -185,7 +185,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
"use strict";
this.name = "oolite-debug-console"; this.name = "oolite-debug-console";
this.author = "Jens Ayton"; this.author = "Jens Ayton";

View File

@ -1,2 +1,3 @@
"use strict";
this.name = "Null AI"; this.name = "Null AI";
// does nothing // does nothing

View File

@ -40,6 +40,7 @@ MA 02110-1301, USA.
#import "OOManifestProperties.h" #import "OOManifestProperties.h"
#import "OOCollectionExtractors.h" #import "OOCollectionExtractors.h"
#import "OOPListParsing.h" #import "OOPListParsing.h"
#import "OODebugStandards.h"
#if OO_CACHE_JS_SCRIPTS #if OO_CACHE_JS_SCRIPTS
#include <jsxdrapi.h> #include <jsxdrapi.h>
@ -706,7 +707,27 @@ static JSScript *LoadScriptWithName(JSContext *context, NSString *path, JSObject
if (script == NULL) if (script == NULL)
{ {
fileContents = [NSString stringWithContentsOfUnicodeFile:path]; fileContents = [NSString stringWithContentsOfUnicodeFile:path];
if (fileContents != nil) data = [fileContents utf16DataWithBOM:NO];
if (fileContents != nil)
{
#ifndef NDEBUG
/* FIXME: this isn't strictly the right test, since strict
* mode can be enabled with this string within a function
* definition, but it seems unlikely anyone is actually doing
* that here. */
if ([fileContents rangeOfString:@"\"use strict\";"].location == NSNotFound && [fileContents rangeOfString:@"'use strict';"].location == NSNotFound)
{
OOStandardsDeprecated([NSString stringWithFormat:@"Script %@ does not \"use strict\";",path]);
if (OOEnforceStandards())
{
// prepend it anyway
// TODO: some time after 1.82, make this required
fileContents = [@"\"use strict\";\n" stringByAppendingString:fileContents];
}
}
#endif
data = [fileContents utf16DataWithBOM:NO];
}
if (data == nil) *outErrorMessage = @"could not load file"; if (data == nil) *outErrorMessage = @"could not load file";
else else
{ {