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 <limits.h>
6#include <stddef.h>
7#include <stdint.h>
8
9#include "include/v8.h"
10#include "test/fuzzer/fuzzer-support.h"
11
12extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
13  v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
14  v8::Isolate* isolate = support->GetIsolate();
15
16  v8::Isolate::Scope isolate_scope(isolate);
17  v8::HandleScope handle_scope(isolate);
18  v8::Context::Scope context_scope(support->GetContext());
19  v8::TryCatch try_catch(isolate);
20
21  if (size > INT_MAX) return 0;
22  v8::Local<v8::String> source;
23  if (!v8::String::NewFromOneByte(isolate, data, v8::NewStringType::kNormal,
24                                  static_cast<int>(size))
25           .ToLocal(&source)) {
26    return 0;
27  }
28
29  v8::JSON::Parse(support->GetContext(), source).IsEmpty();
30  isolate->RequestGarbageCollectionForTesting(
31      v8::Isolate::kFullGarbageCollection);
32  return 0;
33}
34