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

Side by Side Diff: test/fuzzer/parser.cc

Issue 1604203002: Add a library suitable for libfuzzer with a small unit test runner shell (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 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
« no previous file with comments | « test/fuzzer/fuzzer-support.cc ('k') | test/fuzzer/parser/hello-world » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 <stddef.h>
6 #include <stdint.h>
7
8 #include "include/v8.h"
9 #include "src/objects.h"
10 #include "src/parsing/parser.h"
11 #include "src/parsing/preparser.h"
12 #include "test/fuzzer/fuzzer-support.h"
13
14 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
15 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
16 v8::Isolate* isolate = support->GetIsolate();
17
18 v8::Isolate::Scope isolate_scope(isolate);
19 v8::HandleScope handle_scope(isolate);
20 v8::Context::Scope context_scope(support->GetContext());
21 v8::TryCatch try_catch(isolate);
22
23 v8::internal::Isolate* i_isolate =
24 reinterpret_cast<v8::internal::Isolate*>(isolate);
25 v8::internal::Factory* factory = i_isolate->factory();
26
27 if (size > INT_MAX) return 0;
28 v8::internal::MaybeHandle<v8::internal::String> source =
29 factory->NewStringFromOneByte(
30 v8::internal::Vector<const uint8_t>(data, static_cast<int>(size)));
31 if (source.is_null()) return 0;
32
33 v8::internal::Handle<v8::internal::Script> script =
34 factory->NewScript(source.ToHandleChecked());
35 v8::internal::Zone zone;
36 v8::internal::ParseInfo info(&zone, script);
37 info.set_global();
38 v8::internal::Parser parser(&info);
39 parser.Parse(&info);
40 return 0;
41 }
OLDNEW
« no previous file with comments | « test/fuzzer/fuzzer-support.cc ('k') | test/fuzzer/parser/hello-world » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698