Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
chakrashim: Fix build after merge
Browse files Browse the repository at this point in the history
Add stubs for v8 API which are newly required to build node-chakracore

PR-URL: #211
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
Reviewed-By: Hitesh Kanwathirtha <hiteshk@microsoft.com>
  • Loading branch information
boingoing authored and digitalinfinity committed Apr 18, 2017
1 parent ac1e9e0 commit 361c4bb
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 0 deletions.
2 changes: 2 additions & 0 deletions deps/chakrashim/chakrashim.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
'src/v8objecttemplate.cc',
'src/v8persistent.cc',
'src/v8private.cc',
'src/v8promise.cc',
'src/v8propertydescriptor.cc',
'src/v8proxy.cc',
'src/v8script.cc',
Expand All @@ -126,6 +127,7 @@
'src/v8stacktrace.cc',
'src/v8string.cc',
'src/v8stringobject.cc',
'src/v8symbol.cc',
'src/v8template.cc',
'src/v8trycatch.cc',
'src/v8typedarray.cc',
Expand Down
37 changes: 37 additions & 0 deletions deps/chakrashim/include/v8-platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#define V8_V8_PLATFORM_H_

#include <stdint.h>
#include <string>
#include <memory>

namespace v8 {

Expand All @@ -40,6 +42,22 @@ class Task {
virtual void Run() = 0;
};

/**
* The interface represents complex arguments to trace events.
*/
class ConvertableToTraceFormat {
public:
virtual ~ConvertableToTraceFormat() = default;

/**
* Append the class info to the provided |out| string. The appended
* data must be a valid JSON object. Strings must be properly quoted, and
* escaped. There is no processing applied to the content after it is
* appended.
*/
virtual void AppendAsTraceFormat(std::string* out) const = 0;
};

class Platform {
public:
enum ExpectedRuntime {
Expand Down Expand Up @@ -91,6 +109,25 @@ class Platform {
return 0;
}

/**
* Adds a trace event to the platform tracing system. This function call is
* usually the result of a TRACE_* macro from trace_event_common.h when
* tracing and the category of the particular trace are enabled. It is not
* advisable to call this function on its own; it is really only meant to be
* used by the trace macros. The returned handle can be used by
* UpdateTraceEventDuration to update the duration of COMPLETE events.
*/
virtual uint64_t AddTraceEvent(
char phase, const uint8_t* category_enabled_flag, const char* name,
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
const char** arg_names, const uint8_t* arg_types,
const uint64_t* arg_values,
std::unique_ptr<ConvertableToTraceFormat>* arg_convertables,
unsigned int flags) {
return AddTraceEvent(phase, category_enabled_flag, name, scope, id, bind_id,
num_args, arg_names, arg_types, arg_values, flags);
}

/**
* Sets the duration field of a COMPLETE trace event. It must be called with
* the handle returned from AddTraceEvent().
Expand Down
21 changes: 21 additions & 0 deletions deps/chakrashim/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ class Local {
friend class StackTrace;
friend class String;
friend class StringObject;
friend class Symbol;
friend class Utils;
friend class TryCatch;
friend class UnboundScript;
Expand Down Expand Up @@ -1087,6 +1088,7 @@ class V8_EXPORT Boolean : public Primitive {
public:
bool Value() const;
static Handle<Boolean> New(Isolate* isolate, bool value);
static Boolean* Cast(v8::Value* obj);

private:
friend class BooleanObject;
Expand Down Expand Up @@ -1241,6 +1243,18 @@ class V8_EXPORT String : public Name {
};
};

class V8_EXPORT Symbol : public Name {
public:
Local<Value> Name() const;
static Local<Symbol> New(Isolate* isolate,
Local<String> name = Local<String>());
static Symbol* Cast(Value* obj);

private:
static Local<Symbol> From(Local<String> name);
Symbol();
};

class V8_EXPORT Number : public Primitive {
public:
double Value() const;
Expand Down Expand Up @@ -1682,6 +1696,11 @@ class V8_EXPORT Function : public Object {

class V8_EXPORT Promise : public Object {
public:
enum PromiseState { kPending, kFulfilled, kRejected };

Local<Value> Result();
PromiseState State();

class V8_EXPORT Resolver : public Object {
public:
static Local<Resolver> New(Isolate* isolate);
Expand Down Expand Up @@ -2476,6 +2495,8 @@ class Maybe {
bool IsNothing() const { return !has_value; }
bool IsJust() const { return has_value; }

T ToChecked() const { return FromJust(); }

bool To(T* out) const {
if (V8_LIKELY(IsJust())) *out = value;
return IsJust();
Expand Down
5 changes: 5 additions & 0 deletions deps/chakrashim/src/v8boolean.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ Handle<Boolean> Boolean::New(Isolate* isolate, bool value) {
return From(value);
}

Boolean* Boolean::Cast(v8::Value* obj) {
CHAKRA_ASSERT(obj->IsBoolean());
return static_cast<Boolean*>(obj);
}

} // namespace v8
41 changes: 41 additions & 0 deletions deps/chakrashim/src/v8promise.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright Microsoft. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and / or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

#include "v8chakra.h"
#include "jsrtutils.h"

namespace v8 {

Promise::Promise() { }

Local<Value> Promise::Result() {
return Local<Value>();
}

Promise::PromiseState Promise::State() {
return PromiseState::kFulfilled;
}

Promise* Promise::Cast(Value* obj) {
CHAKRA_ASSERT(obj->IsPromise());
return static_cast<Promise*>(obj);
}

} // namespace v8
52 changes: 52 additions & 0 deletions deps/chakrashim/src/v8symbol.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright Microsoft. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and / or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

#include "v8chakra.h"
#include "jsrtutils.h"

namespace v8 {

Symbol::Symbol() { }

Local<Symbol> Symbol::New(Isolate* isolate, Local<String> name) {
return Local<Symbol>::New(isolate, From(name));
}

Local<Symbol> Symbol::From(Local<String> name) {
JsValueRef sym;
JsValueRef description = (JsValueRef)*name;

if (JsCreateSymbol(description, &sym) != JsNoError) {
return Local<Symbol>();
}

return Local<Symbol>::New(static_cast<Symbol*>(sym));
}

Symbol* Symbol::Cast(Value* obj) {
CHAKRA_ASSERT(obj->IsSymbol());
return static_cast<Symbol*>(obj);
}

Local<Value> Symbol::Name() const {
return Local<Value>();
}

} // namespace v8
5 changes: 5 additions & 0 deletions deps/chakrashim/src/v8typedarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ size_t TypedArray::Length() {
return result;
}

TypedArray* TypedArray::Cast(v8::Value* obj) {
CHAKRA_ASSERT(obj->IsTypedArray());
return static_cast<TypedArray*>(obj);
}

JsErrorCode Utils::NewTypedArray(ContextShim::GlobalType constructorIndex,
Handle<ArrayBuffer> array_buffer,
size_t byte_offset, size_t length,
Expand Down

0 comments on commit 361c4bb

Please sign in to comment.