| Index: src/ast.h
|
| diff --git a/src/ast.h b/src/ast.h
|
| index 0115d988272c44e64f326d6f7377619824f2ea41..ff87fa70c26ccf20eaa332a3dd93e8df7b3b7147 100644
|
| --- a/src/ast.h
|
| +++ b/src/ast.h
|
| @@ -78,6 +78,8 @@ namespace internal {
|
| V(Conditional) \
|
| V(VariableProxy) \
|
| V(Literal) \
|
| + V(StringLiteral) \
|
| + V(NumberLiteral) \
|
| V(RegExpLiteral) \
|
| V(ObjectLiteral) \
|
| V(ArrayLiteral) \
|
| @@ -330,15 +332,14 @@ class Expression : public AstNode {
|
| // True iff the expression is a literal represented as a smi.
|
| bool IsSmiLiteral() const;
|
|
|
| - // True iff the expression is a string literal.
|
| - bool IsStringLiteral() const;
|
| -
|
| // True iff the expression is the null literal.
|
| bool IsNullLiteral() const;
|
|
|
| // True if we can prove that the expression is the undefined literal.
|
| bool IsUndefinedLiteral(Isolate* isolate) const;
|
|
|
| + Literal* AsAnyLiteral();
|
| +
|
| // Expression type bounds
|
| Bounds bounds() const { return bounds_; }
|
| void set_bounds(Bounds bounds) { bounds_ = bounds; }
|
| @@ -1328,28 +1329,15 @@ class EmptyStatement V8_FINAL : public Statement {
|
| };
|
|
|
|
|
| -class Literal V8_FINAL : public Expression {
|
| +class Literal : public Expression {
|
| public:
|
| DECLARE_NODE_TYPE(Literal)
|
|
|
| - virtual bool IsPropertyName() const V8_OVERRIDE {
|
| - if (value_->IsInternalizedString()) {
|
| - uint32_t ignored;
|
| - return !String::cast(*value_)->AsArrayIndex(&ignored);
|
| - }
|
| - return false;
|
| - }
|
| -
|
| - Handle<String> AsPropertyName() {
|
| - ASSERT(IsPropertyName());
|
| - return Handle<String>::cast(value_);
|
| - }
|
| -
|
| virtual bool ToBooleanIsTrue() const V8_OVERRIDE {
|
| - return value_->BooleanValue();
|
| + return value()->BooleanValue();
|
| }
|
| virtual bool ToBooleanIsFalse() const V8_OVERRIDE {
|
| - return !value_->BooleanValue();
|
| + return !value()->BooleanValue();
|
| }
|
|
|
| // Identity testers.
|
| @@ -1366,7 +1354,7 @@ class Literal V8_FINAL : public Expression {
|
| return value_->IsFalse();
|
| }
|
|
|
| - Handle<Object> value() const { return value_; }
|
| + virtual Handle<Object> value() const { return value_; }
|
|
|
| // Support for using Literal as a HashMap key. NOTE: Currently, this works
|
| // only for string and number literals!
|
| @@ -1381,20 +1369,83 @@ class Literal V8_FINAL : public Expression {
|
| TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); }
|
|
|
| protected:
|
| + Literal(Zone* zone, int position)
|
| + : Expression(zone, position),
|
| + isolate_(zone->isolate()) {}
|
| Literal(Zone* zone, Handle<Object> value, int position)
|
| : Expression(zone, position),
|
| - value_(value),
|
| - isolate_(zone->isolate()) { }
|
| + isolate_(zone->isolate()),
|
| + value_(value) {}
|
|
|
| - private:
|
| - Handle<String> ToString();
|
| + virtual Handle<String> ToString() const;
|
|
|
| - Handle<Object> value_;
|
| // TODO(dcarney): remove. this is only needed for Match and Hash.
|
| Isolate* isolate_;
|
| +
|
| + private:
|
| + Handle<Object> value_;
|
| +};
|
| +
|
| +
|
| +class StringLiteral V8_FINAL : public Literal {
|
| + public:
|
| + DECLARE_NODE_TYPE(StringLiteral)
|
| +
|
| + virtual bool IsPropertyName() const V8_OVERRIDE {
|
| + uint32_t ignored;
|
| + return !string_->AsArrayIndex(&ignored);
|
| + }
|
| +
|
| + virtual Handle<String> AsPropertyName() const V8_OVERRIDE {
|
| + ASSERT(IsPropertyName());
|
| + return string_;
|
| + }
|
| +
|
| + virtual Handle<Object> value() const V8_OVERRIDE {
|
| + return string_;
|
| + }
|
| +
|
| + virtual Handle<String> string() const V8_OVERRIDE { return string_; }
|
| +
|
| + protected:
|
| + virtual Handle<String> ToString() const V8_OVERRIDE { return string_; }
|
| +
|
| + private:
|
| + StringLiteral(Zone* zone, Handle<String> string,
|
| + int position)
|
| + : Literal(zone, position), string_(string) {}
|
| +
|
| + Handle<String> string_;
|
| };
|
|
|
|
|
| +class NumberLiteral V8_FINAL : public Literal {
|
| + public:
|
| + DECLARE_NODE_TYPE(NumberLiteral)
|
| +
|
| + virtual Handle<Object> value() const V8_OVERRIDE {
|
| + return value_;
|
| + }
|
| +
|
| + double number() const {
|
| + return value_->Number();
|
| + }
|
| +
|
| + protected:
|
| + virtual Handle<String> ToString() const V8_OVERRIDE;
|
| +
|
| + private:
|
| + NumberLiteral(Zone* zone, Handle<Object> value,
|
| + int position)
|
| + : Literal(zone, position), value_(value) {
|
| + ASSERT(value->IsNumber());
|
| + }
|
| +
|
| + Handle<Object> value_;
|
| +};
|
| +
|
| +
|
| +
|
| // Base class for literals that needs space in the corresponding JSFunction.
|
| class MaterializedLiteral : public Expression {
|
| public:
|
| @@ -3128,12 +3179,24 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
|
| }
|
|
|
| Literal* NewLiteral(Handle<Object> handle, int pos) {
|
| + ASSERT(!handle->IsString());
|
| Literal* lit = new(zone_) Literal(zone_, handle, pos);
|
| VISIT_AND_RETURN(Literal, lit)
|
| }
|
|
|
| - Literal* NewNumberLiteral(double number, int pos) {
|
| - return NewLiteral(
|
| + StringLiteral* NewStringLiteral(Handle<String> handle, int pos) {
|
| + StringLiteral* lit = new(zone_) StringLiteral(zone_, handle, pos);
|
| + VISIT_AND_RETURN(StringLiteral, lit)
|
| + }
|
| +
|
| + NumberLiteral* NewNumberLiteral(Handle<Object> handle, int pos) {
|
| + ASSERT(handle->IsNumber());
|
| + NumberLiteral* lit = new(zone_) NumberLiteral(zone_, handle, pos);
|
| + VISIT_AND_RETURN(NumberLiteral, lit)
|
| + }
|
| +
|
| + NumberLiteral* NewNumberLiteral(double number, int pos) {
|
| + return NewNumberLiteral(
|
| zone_->isolate()->factory()->NewNumber(number, TENURED), pos);
|
| }
|
|
|
| @@ -3159,7 +3222,7 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
|
| int pos) {
|
| ObjectLiteral::Property* prop =
|
| new(zone_) ObjectLiteral::Property(zone_, is_getter, value);
|
| - prop->set_key(NewLiteral(value->name(), pos));
|
| + prop->set_key(NewStringLiteral(value->name(), pos));
|
| return prop; // Not an AST node, will not be visited.
|
| }
|
|
|
|
|