Socket
Socket
Sign inDemoInstall

quickjs-emscripten

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quickjs-emscripten - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

8

dist/quickjs.d.ts

@@ -41,2 +41,8 @@ import { QuickJSFFI, JSContextPointer, JSValuePointer, JSRuntimePointer, JSValueConstPointer } from './ffi';

/**
* A Lifetime that lives forever. Used for constants.
*/
export declare class StaticLifetime<T, Owner = never> extends Lifetime<T, Owner> {
dispose(): void;
}
/**
* QuickJSVm wraps a QuickJS Javascript runtime (JSRuntime*) and context (JSContext*).

@@ -208,3 +214,3 @@ * This class's methods return {@link QuickJSHandle}, which wrap C pointers (JSValue*).

*/
export declare type StaticJSValue = Lifetime<JSValueConstPointer>;
export declare type StaticJSValue = StaticLifetime<JSValueConstPointer>;
/**

@@ -211,0 +217,0 @@ * A QuickJSHandle to a borrowed value that does not need to be disposed.

"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -112,7 +125,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

}
this._alive = true;
this._alive = false;
};
Lifetime.prototype.assertAlive = function () {
if (!this._alive) {
throw new Error('Not alive');
if (!this.alive) {
throw new Error('Lifetime not alive');
}

@@ -124,2 +137,15 @@ };

/**
* A Lifetime that lives forever. Used for constants.
*/
var StaticLifetime = /** @class */ (function (_super) {
__extends(StaticLifetime, _super);
function StaticLifetime() {
return _super !== null && _super.apply(this, arguments) || this;
}
// Dispose does nothing.
StaticLifetime.prototype.dispose = function () { };
return StaticLifetime;
}(Lifetime));
exports.StaticLifetime = StaticLifetime;
/**
* QuickJSVm wraps a QuickJS Javascript runtime (JSRuntime*) and context (JSContext*).

@@ -217,3 +243,3 @@ * This class's methods return {@link QuickJSHandle}, which wrap C pointers (JSValue*).

var ptr = this.ffi.QTS_GetUndefined();
return (this._undefined = new Lifetime(ptr));
return (this._undefined = new StaticLifetime(ptr));
},

@@ -238,3 +264,6 @@ enumerable: true,

this.lifetimes.push(this.heapValueHandle(ptr));
this._global = new Lifetime(ptr, undefined, this);
// This isn't technically a static lifetime, but since it has the same
// lifetime as the VM, it's okay to fake one since when the VM iss
// disposed, no other functions will accept the value.
this._global = new StaticLifetime(ptr, undefined, this);
return this._global;

@@ -323,2 +352,3 @@ },

QuickJSVm.prototype.getProp = function (handle, key) {
this.assertOwned(handle);
var quickJSKey = typeof key === 'string' ? this.newString(key) : key;

@@ -345,2 +375,3 @@ var ptr = this.ffi.QTS_GetProp(this.ctx.value, handle.value, quickJSKey.value);

QuickJSVm.prototype.setProp = function (handle, key, value) {
this.assertOwned(handle);
var quickJSKey = typeof key === 'string' ? this.newString(key) : key;

@@ -360,2 +391,3 @@ this.ffi.QTS_SetProp(this.ctx.value, handle.value, quickJSKey.value, value.value);

QuickJSVm.prototype.defineProp = function (handle, key, descriptor) {
this.assertOwned(handle);
var quickJSKey = typeof key === 'string' ? this.newString(key) : key;

@@ -392,2 +424,3 @@ var value = descriptor.value || this.undefined;

}
this.assertOwned(func);
var argsArrayPtr = this.toPointerArray(args);

@@ -430,2 +463,3 @@ var resultPtr = this.ffi.QTS_Call(this.ctx.value, func.value, thisVal.value, args.length, argsArrayPtr.value);

QuickJSVm.prototype.dump = function (handle) {
this.assertOwned(handle);
var type = this.typeof(handle);

@@ -432,0 +466,0 @@ if (type === 'string') {

@@ -114,2 +114,12 @@ "use strict";

});
mocha_1.it('can return undefined twice', function () {
var fnHandle = vm.newFunction('returnUndef', function () {
return vm.undefined;
});
vm.unwrapResult(vm.callFunction(fnHandle, vm.undefined)).dispose();
var result = vm.unwrapResult(vm.callFunction(fnHandle, vm.undefined));
assert_1.default.equal(vm.typeof(result), 'undefined');
result.dispose();
fnHandle.dispose();
});
});

@@ -116,0 +126,0 @@ mocha_1.describe('objects', function () {

2

package.json
{
"name": "quickjs-emscripten",
"version": "0.1.0",
"version": "0.1.1",
"main": "dist/quickjs.js",

@@ -5,0 +5,0 @@ "license": "MIT",

# quickjs-emscripten
Module `quickjs-emscripten` wraps QuickJS, a modern Javascript interpreter
written in C, for usage from Typescript or Javascript. This allows evaluating
untrusted Javascript safely, or even building a plugin system.
`quickjs-emscripten` wraps [QuickJS, a modern Javascript interpreter written in
C](https://bellard.org/quickjs/) for usage from Javascript. This allows
evaluating untrusted Javascript safely, or even building a plugin system for
untrusted code.

@@ -7,0 +8,0 @@ ```typescript

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc