From 4a909a7a62ebe9336366a8453351196e02d2aa5c Mon Sep 17 00:00:00 2001 From: "christian.plesner.hansen@gmail.com" Date: Fri, 24 Apr 2009 12:45:29 +0000 Subject: [PATCH] - When cloning maps to set the 'lazy loading' bit remember to clone the properties as well. This fixes some failing tests. - Moved json parsing into native code. git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1789 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/ast.cc | 21 +++++++++++++++++++++ src/ast.h | 7 +++++++ src/bootstrapper.cc | 4 ++-- src/compiler.cc | 37 +++++++++++++++++++++++++++++++++++-- src/compiler.h | 3 ++- src/debug-delay.js | 2 +- src/factory.cc | 6 +++--- src/factory.h | 2 +- src/handles.cc | 2 +- src/json-delay.js | 29 ++--------------------------- src/objects.cc | 18 +++++++++++------- src/objects.h | 2 +- src/runtime.cc | 21 +++++++++++++++------ src/runtime.h | 2 +- src/v8natives.js | 6 +++--- test/mjsunit/json.js | 8 +++++--- 16 files changed, 111 insertions(+), 59 deletions(-) diff --git a/src/ast.cc b/src/ast.cc index 1a6010a..d19e3b3 100644 --- a/src/ast.cc +++ b/src/ast.cc @@ -152,6 +152,27 @@ ObjectLiteral::Property::Property(bool is_getter, FunctionLiteral* value) { } +bool ObjectLiteral::IsValidJSON() { + int length = properties()->length(); + for (int i = 0; i < length; i++) { + Property* prop = properties()->at(i); + if (!prop->value()->IsValidJSON()) + return false; + } + return true; +} + + +bool ArrayLiteral::IsValidJSON() { + int length = values()->length(); + for (int i = 0; i < length; i++) { + if (!values()->at(i)->IsValidJSON()) + return false; + } + return true; +} + + void TargetCollector::AddTarget(BreakTarget* target) { // Add the label to the collector, but discard duplicates. int length = targets_->length(); diff --git a/src/ast.h b/src/ast.h index b496816..6a2f671 100644 --- a/src/ast.h +++ b/src/ast.h @@ -155,6 +155,7 @@ class Expression: public Node { public: virtual Expression* AsExpression() { return this; } + virtual bool IsValidJSON() { return false; } virtual bool IsValidLeftHandSide() { return false; } // Mark the expression as being compiled as an expression @@ -625,6 +626,8 @@ class Literal: public Expression { return handle_.is_identical_to(other->handle_); } + virtual bool IsValidJSON() { return true; } + // Identity testers. bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); } bool IsTrue() const { return handle_.is_identical_to(Factory::true_value()); } @@ -653,6 +656,8 @@ class MaterializedLiteral: public Expression { // constants and simple object and array literals. bool is_simple() const { return is_simple_; } + virtual bool IsValidJSON() { return true; } + int depth() const { return depth_; } private: @@ -704,6 +709,7 @@ class ObjectLiteral: public MaterializedLiteral { virtual ObjectLiteral* AsObjectLiteral() { return this; } virtual void Accept(AstVisitor* v); + virtual bool IsValidJSON(); Handle constant_properties() const { return constant_properties_; @@ -751,6 +757,7 @@ class ArrayLiteral: public MaterializedLiteral { virtual void Accept(AstVisitor* v); virtual ArrayLiteral* AsArrayLiteral() { return this; } + virtual bool IsValidJSON(); Handle literals() const { return literals_; } ZoneList* values() const { return values_; } diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 31d8c63..c434207 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -530,7 +530,7 @@ void Genesis::CreateRoots(v8::Handle global_template, global_context()->function_instance_map()->set_prototype(*empty_function); // Allocate the function map first and then patch the prototype later - Handle empty_fm = Factory::CopyMap(fm); + Handle empty_fm = Factory::CopyMapDropDescriptors(fm); empty_fm->set_instance_descriptors(*function_map_descriptors); empty_fm->set_prototype(global_context()->object_function()->prototype()); empty_function->set_map(*empty_fm); @@ -1433,7 +1433,7 @@ void Genesis::MakeFunctionInstancePrototypeWritable() { Handle function_map_descriptors = ComputeFunctionInstanceDescriptor(false, true); - Handle fm = Factory::CopyMap(Top::function_map()); + Handle fm = Factory::CopyMapDropDescriptors(Top::function_map()); fm->set_instance_descriptors(*function_map_descriptors); Top::context()->global_context()->set_function_map(*fm); } 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 Handle MakeCode(FunctionLiteral* literal, } +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 MakeFunction(bool is_global, bool is_eval, + bool is_json, Handle