From: marja@chromium.org Date: Mon, 30 Jun 2014 13:35:16 +0000 (+0000) Subject: Parser: add usage counters for "use asm". X-Git-Tag: upstream/4.7.83~8476 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=570a0bf8f54ccb3b9dfc3fc69779294f5b848eec;p=platform%2Fupstream%2Fv8.git Parser: add usage counters for "use asm". R=jochen@chromium.org BUG= Review URL: https://codereview.chromium.org/336863007 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22093 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/include/v8.h b/include/v8.h index 7d27029..6607c45 100644 --- a/include/v8.h +++ b/include/v8.h @@ -4134,7 +4134,8 @@ class V8_EXPORT Isolate { * list. */ enum UseCounterFeature { - kUseAsm = 0 + kUseAsm = 0, + kUseCounterFeatureCount // This enum value must be last. }; typedef void (*UseCounterCallback)(Isolate* isolate, diff --git a/src/ast-value-factory.h b/src/ast-value-factory.h index e70271f..4711bb4 100644 --- a/src/ast-value-factory.h +++ b/src/ast-value-factory.h @@ -260,6 +260,7 @@ class AstValue : public ZoneObject { F(proto, "__proto__") \ F(prototype, "prototype") \ F(this, "this") \ + F(use_asm, "use asm") \ F(use_strict, "use strict") \ F(value, "value") diff --git a/src/parser.cc b/src/parser.cc index a04db36..d882c1e 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -783,6 +783,10 @@ Parser::Parser(CompilationInfo* info) set_allow_generators(FLAG_harmony_generators); set_allow_for_of(FLAG_harmony_iteration); set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); + for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; + ++feature) { + use_counts_[feature] = 0; + } } @@ -1087,11 +1091,13 @@ void* Parser::ParseSourceElements(ZoneList* processor, if ((e_stat = stat->AsExpressionStatement()) != NULL && (literal = e_stat->expression()->AsLiteral()) != NULL && literal->raw_value()->IsString()) { - // Check "use strict" directive (ES5 14.1). + // Check "use strict" directive (ES5 14.1) and "use asm" directive. Only + // one can be present. if (strict_mode() == SLOPPY && literal->raw_value()->AsString() == ast_value_factory_->use_strict_string() && - token_loc.end_pos - token_loc.beg_pos == 12) { + token_loc.end_pos - token_loc.beg_pos == + ast_value_factory_->use_strict_string()->length() + 2) { // TODO(mstarzinger): Global strict eval calls, need their own scope // as specified in ES5 10.4.2(3). The correct fix would be to always // add this scope in DoParseProgram(), but that requires adaptations @@ -1108,6 +1114,13 @@ void* Parser::ParseSourceElements(ZoneList* processor, scope_->SetStrictMode(STRICT); // "use strict" is the only directive for now. directive_prologue = false; + } else if (literal->raw_value()->AsString() == + ast_value_factory_->use_asm_string() && + token_loc.end_pos - token_loc.beg_pos == + ast_value_factory_->use_asm_string()->length() + 2) { + // Store the usage count; The actual use counter on the isolate is + // incremented after parsing is done. + ++use_counts_[v8::Isolate::kUseAsm]; } } else { // End of the directive prologue. @@ -3899,6 +3912,16 @@ void Parser::ThrowPendingError() { } +void Parser::InternalizeUseCounts() { + for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; + ++feature) { + for (int i = 0; i < use_counts_[feature]; ++i) { + isolate()->CountUsage(v8::Isolate::UseCounterFeature(feature)); + } + } +} + + // ---------------------------------------------------------------------------- // Regular expressions @@ -4840,6 +4863,9 @@ bool Parser::Parse() { info()->SetAstValueFactory(ast_value_factory_); } ast_value_factory_ = NULL; + + InternalizeUseCounts(); + return (result != NULL); } diff --git a/src/parser.h b/src/parser.h index c05b2d9..346f75f 100644 --- a/src/parser.h +++ b/src/parser.h @@ -798,6 +798,8 @@ class Parser : public ParserBase { void ThrowPendingError(); + void InternalizeUseCounts(); + Isolate* isolate_; Handle