Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from mbbill:master #2

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .gclient
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# dummy file, just to make depot_tools/gn.py happy
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
38 changes: 17 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
.DS_Store
*.bc
*.obj
*.tlog
*.dll
*.db
*.exp
*.lib
*.pdb
*.idb
*.ilk
*.ipdb
/Release/
/Debug/
*.user
*.lib
*.log
*.idb
vsproj/x64/
vsproj/.vs/
*.db
*.pyc
*.obj
*.opendb
Source/JavaScriptCore/DerivedSources/JavaScriptCore/
.vs/
*.pdb
*.pyc
*.tlog
*.tmp
*.ilk
*.user
.DS_Store
.vs/
/Debug/
/Release/
out/
build/gn/external_bin/
build/gn/win/
build/gn/linux/
build/gn/mac/
vsproj/.vs/
vsproj/x64/
*.sln
*.cache
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
**JSC.js** is a JavaScript engine which can run on top of you browser's JavaScript engine. It's based on the JavaScript engine (JavaScriptCore) of WebKit and compiled to wasm with emscripten. Therefore, if you're using Safari, you are literally running its JavaScript engine on top of itself.
**JSC.js** is a JavaScript engine that can run on top of your browser's JavaScript engine. It's based on the JavaScript engine (JavaScriptCore) of WebKit and compiled to wasm with emscripten. Therefore, if you're using Safari, you are running its JavaScript engine on top of itself.

The size of JSC.wasm is around 4MB (compressed js and mem file).

## Demo: [Link](https://mbbill.github.io/JSC.js/demo/index.html)

## ScreenShot
![](https://sites.google.com/site/mbbill/jsc3.png)
![](demo/jsc3.png)

## Build
### Preparation
- install emscripten
- install python, ruby, ninja, etc.
- run `build/gn/download.bat` to download latest `gn.exe`.
- run `Source/JavaScriptCore/DerivedSources/gen.bat` to generate derived sources.
- start a terminal.
- go to emsdk installation path and run `emsdk_env.bat`
- go to JSC.js folder and run `prep_env.bat`

### Build with gn
```
> gn gen out --args="target_os=\"wasm\""
> ninja -C out
```

### Build test shell on Windows
## Build test shell on Windows

Usually, you don't need this but with the test shell, you can easily debug and test JSC.js on windows when there's no good debugger for JSC.js on wasm.

### Preparation

- install python, ruby, etc.
- start a terminal.
- install visual studio
- run `vcvarsall.bat amd64` in terminal

### Build with gn

```
> gn gen out --args="target_os=\"win\""
> ninja -C out
Expand Down
37 changes: 24 additions & 13 deletions Source/JavaScriptCore/API/APICast.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "JSCJSValue.h"
#include "JSCJSValueInlines.h"
#include "JSGlobalObject.h"
#include "HeapCellInlines.h"

namespace JSC {
class ExecState;
Expand Down Expand Up @@ -60,10 +61,15 @@ inline JSC::ExecState* toJS(JSGlobalContextRef c)
return reinterpret_cast<JSC::ExecState*>(c);
}

inline JSC::JSGlobalObject* toJSGlobalObject(JSGlobalContextRef context)
{
return toJS(context)->lexicalGlobalObject();
}

inline JSC::JSValue toJS(JSC::ExecState* exec, JSValueRef v)
{
ASSERT_UNUSED(exec, exec);
#if USE(JSVALUE32_64)
#if !CPU(ADDRESS64)
JSC::JSCell* jsCell = reinterpret_cast<JSC::JSCell*>(const_cast<OpaqueJSValue*>(v));
if (!jsCell)
return JSC::jsNull();
Expand All @@ -73,28 +79,28 @@ inline JSC::JSValue toJS(JSC::ExecState* exec, JSValueRef v)
else
result = jsCell;
#else
JSC::JSValue result = JSC::JSValue::decode(reinterpret_cast<JSC::EncodedJSValue>(const_cast<OpaqueJSValue*>(v)));
JSC::JSValue result = bitwise_cast<JSC::JSValue>(v);
#endif
if (!result)
return JSC::jsNull();
if (result.isCell())
RELEASE_ASSERT(result.asCell()->methodTable());
RELEASE_ASSERT(result.asCell()->methodTable(exec->vm()));
return result;
}

inline JSC::JSValue toJSForGC(JSC::ExecState* exec, JSValueRef v)
{
ASSERT_UNUSED(exec, exec);
#if USE(JSVALUE32_64)
#if !CPU(ADDRESS64)
JSC::JSCell* jsCell = reinterpret_cast<JSC::JSCell*>(const_cast<OpaqueJSValue*>(v));
if (!jsCell)
return JSC::JSValue();
JSC::JSValue result = jsCell;
#else
JSC::JSValue result = JSC::JSValue::decode(reinterpret_cast<JSC::EncodedJSValue>(const_cast<OpaqueJSValue*>(v)));
JSC::JSValue result = bitwise_cast<JSC::JSValue>(v);
#endif
if (result && result.isCell())
RELEASE_ASSERT(result.asCell()->methodTable());
RELEASE_ASSERT(result.asCell()->methodTable(exec->vm()));
return result;
}

Expand All @@ -108,7 +114,7 @@ inline JSC::JSObject* toJS(JSObjectRef o)
{
JSC::JSObject* object = uncheckedToJS(o);
if (object)
RELEASE_ASSERT(object->methodTable());
RELEASE_ASSERT(object->methodTable(*object->vm()));
return object;
}

Expand All @@ -122,21 +128,26 @@ inline JSC::VM* toJS(JSContextGroupRef g)
return reinterpret_cast<JSC::VM*>(const_cast<OpaqueJSContextGroup*>(g));
}

inline JSValueRef toRef(JSC::ExecState* exec, JSC::JSValue v)
inline JSValueRef toRef(JSC::VM& vm, JSC::JSValue v)
{
ASSERT(exec->vm().currentThreadIsHoldingAPILock());
#if USE(JSVALUE32_64)
ASSERT(vm.currentThreadIsHoldingAPILock());
#if !CPU(ADDRESS64)
if (!v)
return 0;
if (!v.isCell())
return reinterpret_cast<JSValueRef>(JSC::jsAPIValueWrapper(exec, v).asCell());
return reinterpret_cast<JSValueRef>(JSC::JSAPIValueWrapper::create(vm, v));
return reinterpret_cast<JSValueRef>(v.asCell());
#else
UNUSED_PARAM(exec);
return reinterpret_cast<JSValueRef>(JSC::JSValue::encode(v));
UNUSED_PARAM(vm);
return bitwise_cast<JSValueRef>(v);
#endif
}

inline JSValueRef toRef(JSC::ExecState* exec, JSC::JSValue v)
{
return toRef(exec->vm(), v);
}

inline JSObjectRef toRef(JSC::JSObject* o)
{
return reinterpret_cast<JSObjectRef>(o);
Expand Down
10 changes: 5 additions & 5 deletions Source/JavaScriptCore/API/APIUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#ifndef APIUtils_h
#define APIUtils_h

#include "CatchScope.h"
#include "Exception.h"
#include "JSCJSValue.h"
#include "JSGlobalObjectInspectorController.h"
Expand All @@ -36,17 +37,15 @@ enum class ExceptionStatus {
DidNotThrow
};

inline ExceptionStatus handleExceptionIfNeeded(JSC::ExecState* exec, JSValueRef* returnedExceptionRef)
inline ExceptionStatus handleExceptionIfNeeded(JSC::CatchScope& scope, JSC::ExecState* exec, JSValueRef* returnedExceptionRef)
{
JSC::VM& vm = exec->vm();
auto scope = DECLARE_CATCH_SCOPE(vm);
if (UNLIKELY(scope.exception())) {
JSC::Exception* exception = scope.exception();
if (returnedExceptionRef)
*returnedExceptionRef = toRef(exec, exception->value());
scope.clearException();
#if ENABLE(REMOTE_INSPECTOR)
exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exception);
scope.vm().vmEntryGlobalObject(exec)->inspectorController().reportAPIException(exec, exception);
#endif
return ExceptionStatus::DidThrow;
}
Expand All @@ -58,7 +57,8 @@ inline void setException(JSC::ExecState* exec, JSValueRef* returnedExceptionRef,
if (returnedExceptionRef)
*returnedExceptionRef = toRef(exec, exception);
#if ENABLE(REMOTE_INSPECTOR)
exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, JSC::Exception::create(exec->vm(), exception));
JSC::VM& vm = exec->vm();
vm.vmEntryGlobalObject(exec)->inspectorController().reportAPIException(exec, JSC::Exception::create(vm, exception));
#endif
}

Expand Down
54 changes: 54 additions & 0 deletions Source/JavaScriptCore/API/JSAPIGlobalObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2019 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "JSAPIGlobalObject.h"

#if !JSC_OBJC_API_ENABLED

namespace JSC {

const ClassInfo JSAPIGlobalObject::s_info = { "GlobalObject", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSAPIGlobalObject) };

const GlobalObjectMethodTable JSAPIGlobalObject::s_globalObjectMethodTable = {
&supportsRichSourceInfo,
&shouldInterruptScript,
&javaScriptRuntimeFlags,
nullptr, // queueTaskToEventLoop
&shouldInterruptScriptBeforeTimeout,
nullptr, // moduleLoaderImportModule
nullptr, // moduleLoaderResolve
nullptr, // moduleLoaderFetch
nullptr, // moduleLoaderCreateImportMetaProperties
nullptr, // moduleLoaderEvaluate
nullptr, // promiseRejectionTracker
nullptr, // defaultLanguage
nullptr, // compileStreaming
nullptr, // instantiateStreaming
};

}

#endif
Loading