Push version 1.2.1 to trunk.
Added EcmaScript 5 JSON object.
Fix bug in preemption support on ARM.
git-svn-id: http://v8.googlecode.com/svn/trunk@1797 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
diff --git a/src/compiler.cc b/src/compiler.cc
index 62e838e..c16b938 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -80,8 +80,20 @@
}
+static bool IsValidJSON(FunctionLiteral* lit) {
+ if (!lit->body()->length() == 1)
+ return false;
+ Statement* stmt = lit->body()->at(0);
+ if (stmt->AsExpressionStatement() == NULL)
+ return false;
+ Expression *expr = stmt->AsExpressionStatement()->expression();
+ return expr->IsValidJSON();
+}
+
+
static Handle<JSFunction> MakeFunction(bool is_global,
bool is_eval,
+ bool is_json,
Handle<Script> script,
Handle<Context> context,
v8::Extension* extension,
@@ -109,6 +121,19 @@
return Handle<JSFunction>::null();
}
+ // When parsing JSON we do an ordinary parse and then afterwards
+ // check the AST to ensure it was well-formed. If not we give a
+ // syntax error.
+ if (is_json && !IsValidJSON(lit)) {
+ HandleScope scope;
+ Handle<JSArray> args = Factory::NewJSArray(1);
+ Handle<Object> source(script->source());
+ SetElement(args, 0, source);
+ Handle<Object> result = Factory::NewSyntaxError("invalid_json", args);
+ Top::Throw(*result, NULL);
+ return Handle<JSFunction>::null();
+ }
+
// Measure how long it takes to do the compilation; only take the
// rest of the function into account to avoid overlap with the
// parsing statistics.
@@ -215,6 +240,7 @@
// Compile the function and add it to the cache.
result = MakeFunction(true,
false,
+ false,
script,
Handle<Context>::null(),
extension,
@@ -237,7 +263,8 @@
Handle<JSFunction> Compiler::CompileEval(Handle<String> source,
Handle<Context> context,
int line_offset,
- bool is_global) {
+ bool is_global,
+ bool is_json) {
int source_length = source->length();
Counters::total_eval_size.Increment(source_length);
Counters::total_compile_size.Increment(source_length);
@@ -256,7 +283,13 @@
// Create a script object describing the script to be compiled.
Handle<Script> script = Factory::NewScript(source);
script->set_line_offset(Smi::FromInt(line_offset));
- result = MakeFunction(is_global, true, script, context, NULL, NULL);
+ result = MakeFunction(is_global,
+ true,
+ is_json,
+ script,
+ context,
+ NULL,
+ NULL);
if (!result.is_null()) {
CompilationCache::PutEval(source, context, entry, result);
}