Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: src/pending-compilation-error-handler.cc

Issue 943543002: [strong] Declaration-after-use errors. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: more fixes + tests Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/pending-compilation-error-handler.h"
6
7 #include "src/debug.h"
8 #include "src/handles.h"
9 #include "src/isolate.h"
10 #include "src/messages.h"
11
12 namespace v8 {
13 namespace internal {
14
15 void PendingCompilationErrorHandler::ThrowPendingError(Isolate* isolate,
16 Handle<Script> script) {
17 if (!has_pending_error_) return;
18 MessageLocation location(script, start_position_, end_position_);
19 Factory* factory = isolate->factory();
20 bool has_arg = arg_ != NULL || char_arg_ != NULL;
21 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0);
22 if (arg_ != NULL) {
23 Handle<String> arg_string = arg_->string();
24 elements->set(0, *arg_string);
25 } else if (char_arg_ != NULL) {
26 Handle<String> arg_string =
27 factory->NewStringFromUtf8(CStrVector(char_arg_)).ToHandleChecked();
28 elements->set(0, *arg_string);
29 }
30 isolate->debug()->OnCompileError(script);
31
32 Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
33 Handle<Object> error;
34
35 MaybeHandle<Object> maybe_error;
36 switch (error_type_) {
37 case kReferenceError:
38 maybe_error = factory->NewReferenceError(message_, array);
39 break;
40 case kSyntaxError:
41 maybe_error = factory->NewSyntaxError(message_, array);
42 break;
43 }
44 DCHECK(!maybe_error.is_null() || isolate->has_pending_exception());
45
46 if (maybe_error.ToHandle(&error)) {
47 Handle<JSObject> jserror = Handle<JSObject>::cast(error);
48
49 Handle<Name> key_start_pos = factory->error_start_pos_symbol();
50 JSObject::SetProperty(jserror, key_start_pos,
51 handle(Smi::FromInt(location.start_pos()), isolate),
52 SLOPPY).Check();
53
54 Handle<Name> key_end_pos = factory->error_end_pos_symbol();
55 JSObject::SetProperty(jserror, key_end_pos,
56 handle(Smi::FromInt(location.end_pos()), isolate),
57 SLOPPY).Check();
58
59 Handle<Name> key_script = factory->error_script_symbol();
60 JSObject::SetProperty(jserror, key_script, script, SLOPPY).Check();
61
62 isolate->Throw(*error, &location);
63 }
64 }
65 }
66 } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698