Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "none",
"comment": "Introduce ChakraPointerValue and reimplement many Runtime functions with it.",
"packageName": "react-native-windows",
"email": "yicyao@microsoft.com",
"commit": "af2be74461b33fa6fdcafbb53d4f4388b16a98d6",
"date": "2019-10-17T00:50:01.129Z",
"file": "D:\\Git\\hansenyy-react-native-windows-3\\change\\react-native-windows-2019-10-16-17-50-01-CharkaObjectRef.json"
}
21 changes: 6 additions & 15 deletions vnext/JSI.Desktop.UnitTests/JsiRuntimeUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ TEST_P(JsiRuntimeUnitTests, RuntimeTest) {
EXPECT_EQ(rt.global().getProperty(rt, "x").getNumber(), 1);
}

// TODO (yicyao) #2703: Currently, comparison of property IDs is broken for
// ChakraRuntime. Enable this test once we fix it.
TEST_P(JsiRuntimeUnitTests, DISABLED_PropNameIDTest) {
TEST_P(JsiRuntimeUnitTests, PropNameIDTest) {
// This is a little weird to test, because it doesn't really exist
// in JS yet. All I can do is create them, compare them, and
// receive one as an argument to a HostObject.
Expand Down Expand Up @@ -926,9 +924,6 @@ TEST_P(JsiRuntimeUnitTests, DISABLED_ExceptionStackTraceTest) {
EXPECT_NE(stack.find("world"), std::string::npos);
}

// TODO (T28293178) Remove this once exceptions are supported in all builds.
#ifndef JSI_NO_EXCEPTION_TESTS

namespace {

unsigned countOccurences(const std::string &of, const std::string &in) {
Expand All @@ -944,7 +939,7 @@ unsigned countOccurences(const std::string &of, const std::string &in) {
} // namespace

TEST_P(JsiRuntimeUnitTests, JSErrorsArePropagatedNicely) {
unsigned callsBeoreError = 5;
unsigned callsBeforeError = 5;

Function sometimesThrows = function(
"function sometimesThrows(shouldThrow, callback) {"
Expand All @@ -958,25 +953,21 @@ TEST_P(JsiRuntimeUnitTests, JSErrorsArePropagatedNicely) {
rt,
PropNameID::forAscii(rt, "callback"),
0,
[&sometimesThrows, &callsBeoreError](
[&sometimesThrows, &callsBeforeError](
Runtime &rt, const Value &thisVal, const Value *args, size_t count) {
return sometimesThrows.call(rt, --callsBeoreError == 0, args[0]);
return sometimesThrows.call(rt, --callsBeforeError == 0, args[0]);
});

try {
sometimesThrows.call(rt, false, callback);
} catch (JSError &error) {
// TODO (yicyao): Need to fix getMessage().
// EXPECT_EQ(error.getMessage(), "Omg, what a nasty exception");

// TODO (yicyao): Need to fix getStack().
// EXPECT_EQ(countOccurences("sometimesThrows", error.getStack()), 6);
EXPECT_EQ(error.getMessage(), "Omg, what a nasty exception");
EXPECT_EQ(countOccurences("sometimesThrows", error.getStack()), 6);

// system JSC JSI does not implement host function names
// EXPECT_EQ(countOccurences("callback", error.getStack(rt)), 5);
}
}
#endif

TEST_P(JsiRuntimeUnitTests, JSErrorsCanBeConstructedWithStack) {
auto err = JSError(rt, "message", "stack");
Expand Down
65 changes: 19 additions & 46 deletions vnext/JSI/Desktop/ChakraJsiRuntime_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

#include "ChakraRuntime.h"
#include "ChakraRuntimeFactory.h"
#include "Unicode.h"

#include <cxxreact/MessageQueueThread.h>
#include "ByteArrayBuffer.h"
#include "Unicode.h"

// This file contains non-edge-mode (or win32) implementations.
#if !defined(USE_EDGEMODE_JSRT)
Expand Down Expand Up @@ -35,35 +36,8 @@ struct FileVersionInfoResource {

} // namespace

JsWeakRef ChakraRuntime::newWeakObjectRef(const facebook::jsi::Object &obj) {
JsWeakRef weakRef;
JsCreateWeakReference(objectRef(obj), &weakRef);
return weakRef;
}

JsValueRef ChakraRuntime::strongObjectRef(
const facebook::jsi::WeakObject &obj) {
JsValueRef strongRef;
JsGetWeakReferenceValue(objectRef(obj), &strongRef);
return strongRef;
}

// Note :: ChakraCore header provides an API which takes 8-bit string .. which
// is not available in edge mode.
JsValueRef ChakraRuntime::createJSString(const char *data, size_t length) {
JsValueRef value;
JsCreateString(reinterpret_cast<const char *>(data), length, &value);
return value;
}

// Note :: ChakraCore header provides an API which takes 8-bit string .. which
// is not available in edge mode.
JsValueRef ChakraRuntime::createJSPropertyId(const char *data, size_t length) {
JsValueRef propIdRef;
if (JsNoError != JsCreatePropertyId(data, length, &propIdRef))
std::terminate();
return propIdRef;
}
// TODO (yicyao): We temporarily removed weak reference semantics from
// ChakraCore based jsi::Runtime.

// ES6 Promise callback
void CALLBACK ChakraRuntime::PromiseContinuationCallback(
Expand All @@ -88,7 +62,8 @@ void ChakraRuntime::PromiseContinuation(JsValueRef funcRef) noexcept {
runtimeArgs().jsQueue->runOnQueue([this, funcRef]() {
JsValueRef undefinedValue;
JsGetUndefinedValue(&undefinedValue);
checkException(JsCallFunction(funcRef, &undefinedValue, 1, nullptr));
VerifyJsErrorElseThrow(
JsCallFunction(funcRef, &undefinedValue, 1, nullptr));
JsRelease(funcRef, nullptr);
});
}
Expand All @@ -111,7 +86,7 @@ void ChakraRuntime::PromiseRejectionTracker(
JsValueRef stackStrValue;
error = JsConvertValueToString(stack, &stackStrValue);
if (error == JsNoError) {
errorStream << JSStringToSTLString(stackStrValue);
errorStream << ToStdString(ChakraObjectRef(stackStrValue));
}
}
}
Expand All @@ -121,7 +96,7 @@ void ChakraRuntime::PromiseRejectionTracker(
JsValueRef strValue;
error = JsConvertValueToString(reason, &strValue);
if (error == JsNoError) {
errorStream << JSStringToSTLString(strValue);
errorStream << ToStdString(ChakraObjectRef(strValue));
}
}

Expand Down Expand Up @@ -325,16 +300,14 @@ facebook::jsi::Value ChakraRuntime::evaluateJavaScriptSimple(
&sourceURLRef);

JsValueRef result;
checkException(
JsRun(
sourceRef,
0,
sourceURLRef,
JsParseScriptAttributes::JsParseScriptAttributeNone,
&result),
sourceURL.c_str());

return createValue(result);
VerifyJsErrorElseThrow(JsRun(
sourceRef,
0,
sourceURLRef,
JsParseScriptAttributes::JsParseScriptAttributeNone,
&result));

return ToJsiValue(ChakraObjectRef(result));
}

// TODO :: Return result
Expand All @@ -351,8 +324,8 @@ bool ChakraRuntime::evaluateSerializedScript(
&bytecodeArrayBuffer) == JsNoError) {
JsValueRef sourceURLRef = nullptr;
if (!sourceURL.empty()) {
sourceURLRef = createJSString(
reinterpret_cast<const char *>(sourceURL.c_str()), sourceURL.size());
sourceURLRef = ToJsString(std::string_view{
reinterpret_cast<const char *>(sourceURL.c_str()), sourceURL.size()});
}

JsValueRef value = nullptr;
Expand Down Expand Up @@ -383,7 +356,7 @@ bool ChakraRuntime::evaluateSerializedScript(
} else if (result == JsErrorBadSerializedScript) {
return false;
} else {
checkException(result);
VerifyChakraErrorElseThrow(result);
}
}

Expand Down
3 changes: 2 additions & 1 deletion vnext/JSI/Shared/ByteArrayBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

#pragma once

#include <memory>
#include "jsi/jsi.h"

#include <memory>

namespace Microsoft::JSI {

class ByteArrayBuffer final : public facebook::jsi::Buffer {
Expand Down
Loading