<commit_before>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "config.h"

#include "bindings/core/v8/ScriptState.h"
#include "bindings/core/v8/WorkerThreadDebugger.h"
#include "v8inspector/V8Inspector.h"
#include "v8inspector/RemoteDebuggingServer.h"
#include "wtf/OwnPtr.h"

#include <include/v8.h>
#include <include/libplatform/libplatform.h>

#include "base/message_loop/message_loop.h"
#include "base/at_exit.h"
#include "base/run_loop.h"
#include "base/threading/thread.h"
#include "base/bind.h"

#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace blink;
using namespace v8inspector;

/**
 * This sample program shows how to implement a simple javascript shell
 * based on V8.  This includes initializing V8 with command line options,
 * creating global functions, compiling and executing strings.
 *
 * For a more sophisticated shell, consider using the debug shell D8.
 */


v8::Handle<v8::Context> CreateShellContext(v8::Isolate* isolate);
void RunShell(v8::Handle<v8::Context> context);
int RunMain(v8::Isolate* isolate, int argc, char* argv[]);
bool ExecuteString(v8::Isolate* isolate,
                   v8::Handle<v8::String> source,
                   v8::Handle<v8::Value> name,
                   bool print_result,
                   bool report_exceptions);
void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name);
void ReportException(v8::Isolate* isolate, v8::TryCatch* handler);


static bool run_shell;

namespace {

class DebuggerMessageLoopImpl : public WorkerThreadDebugger::ClientMessageLoop {
 public:
  DebuggerMessageLoopImpl() : message_loop_(base::MessageLoop::current()) {}
  virtual ~DebuggerMessageLoopImpl() { message_loop_ = NULL; }
  void run() override {
    base::MessageLoop::ScopedNestableTaskAllower allow(message_loop_);
    message_loop_->Run();
  }
  void quitNow() override {
    message_loop_->QuitNow();
  }
 private:
  base::MessageLoop* message_loop_;
};

class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
 public:
  void* Allocate(size_t length) override {
    void* data = AllocateUninitialized(length);
    return data == NULL ? data : memset(data, 0, length);
  }
  void* AllocateUninitialized(size_t length) override { return malloc(length); }
  void Free(void* data, size_t) override { free(data); }
};


static void runMainTask(v8::Isolate* isolate, int argc, char* argv[], int* result)
{
    fprintf(stderr, "runMainTask >>\n");
    *result = RunMain(isolate, argc, argv);
    if (run_shell) {
        v8::Local<v8::Context> context = isolate->GetCurrentContext();
        RunShell(context);
    }
    fprintf(stderr, "runMainTask <<\n");
}

}

int main(int argc, char* argv[]) {
  base::AtExitManager at_exit;
  base::MessageLoop message_loop;

  v8::V8::InitializeICU();
  v8::Platform* platform = v8::platform::CreateDefaultPlatform();
  v8::V8::InitializePlatform(platform);
  v8::V8::Initialize();
  v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
  ShellArrayBufferAllocator array_buffer_allocator;
  v8::Isolate::CreateParams create_params;
  create_params.array_buffer_allocator = &array_buffer_allocator;
  v8::Isolate* isolate = v8::Isolate::New(create_params);

  run_shell = (argc == 1);

  fprintf(stderr, "main 10\n");
  int result;
  {
    v8::Isolate::Scope isolate_scope(isolate);
    v8::HandleScope handle_scope(isolate);
    v8::Handle<v8::Context> context = CreateShellContext(isolate);
    if (context.IsEmpty()) {
      fprintf(stderr, "Error creating context\n");
      return 1;
    }
    v8::Context::Scope context_scope(context);

    // Must be in context when constructing V8Inspector.<commit_msg>Show already compiled scripts in the debugger<commit_after>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "config.h"

#include "bindings/core/v8/ScriptState.h"
#include "bindings/core/v8/WorkerThreadDebugger.h"
#include "v8inspector/V8Inspector.h"
#include "v8inspector/RemoteDebuggingServer.h"
#include "wtf/OwnPtr.h"

#include <include/v8.h>
#include <include/libplatform/libplatform.h>

#include "base/message_loop/message_loop.h"
#include "base/at_exit.h"
#include "base/run_loop.h"
#include "base/threading/thread.h"
#include "base/bind.h"

#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace blink;
using namespace v8inspector;

/**
 * This sample program shows how to implement a simple javascript shell
 * based on V8.  This includes initializing V8 with command line options,
 * creating global functions, compiling and executing strings.
 *
 * For a more sophisticated shell, consider using the debug shell D8.
 */


v8::Handle<v8::Context> CreateShellContext(v8::Isolate* isolate);
void RunShell(v8::Handle<v8::Context> context);
int RunMain(v8::Isolate* isolate, int argc, char* argv[]);
bool ExecuteString(v8::Isolate* isolate,
                   v8::Handle<v8::String> source,
                   v8::Handle<v8::Value> name,
                   bool print_result,
                   bool report_exceptions);
void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name);
void ReportException(v8::Isolate* isolate, v8::TryCatch* handler);


static bool run_shell;

namespace {

class DebuggerMessageLoopImpl : public WorkerThreadDebugger::ClientMessageLoop {
 public:
  DebuggerMessageLoopImpl() : message_loop_(base::MessageLoop::current()) {}
  virtual ~DebuggerMessageLoopImpl() { message_loop_ = NULL; }
  void run() override {
    base::MessageLoop::ScopedNestableTaskAllower allow(message_loop_);
    message_loop_->Run();
  }
  void quitNow() override {
    message_loop_->QuitNow();
  }
 private:
  base::MessageLoop* message_loop_;
};

class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
 public:
  void* Allocate(size_t length) override {
    void* data = AllocateUninitialized(length);
    return data == NULL ? data : memset(data, 0, length);
  }
  void* AllocateUninitialized(size_t length) override { return malloc(length); }
  void Free(void* data, size_t) override { free(data); }
};


static void runMainTask(v8::Isolate* isolate, int argc, char* argv[], int* result)
{
    *result = RunMain(isolate, argc, argv);
    if (run_shell) {
        v8::Local<v8::Context> context = isolate->GetCurrentContext();
        RunShell(context);
    }
}

}

int main(int argc, char* argv[]) {
  base::AtExitManager at_exit;
  base::MessageLoop message_loop;

  v8::V8::InitializeICU();
  v8::Platform* platform = v8::platform::CreateDefaultPlatform();
  v8::V8::InitializePlatform(platform);
  v8::V8::Initialize();
  v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
  ShellArrayBufferAllocator array_buffer_allocator;
  v8::Isolate::CreateParams create_params;
  create_params.array_buffer_allocator = &array_buffer_allocator;
  v8::Isolate* isolate = v8::Isolate::New(create_params);

  run_shell = (argc == 1);

  fprintf(stderr, "main 10\n");
  int result;
  {
    v8::Isolate::Scope isolate_scope(isolate);
    v8::HandleScope handle_scope(isolate);
    v8::Handle<v8::Context> context = CreateShellContext(isolate);
    // Set context deubg data to see its scripts in the debugger.
    WorkerThreadDebugger::setContextDebugData(context);
    if (context.IsEmpty()) {
      fprintf(stderr, "Error creating context\n");
      return 1;
    }
    v8::Context::Scope context_scope(context);

    // Must be in context when constructing V8Inspector.
{'fraction_non_alphanumeric': 0.13140794223826716, 'fraction_numerical': 0.016365824308062576, 'mean_word_length': 5.035584604212056, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3614582', 'n_tokens_mistral': 2713, 'n_tokens_neox': 2656, 'n_words': 629}