1 Star 0 Fork 1

weimingtom/v7

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
v7.h 54.87 KB
一键复制 编辑 原始数据 按行查看 历史
Marko Mikulicic 提交于 2016-10-25 16:27 +08:00 . Expose a non nul-terminated exec
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086
#ifdef V7_MODULE_LINES
#line 1 "v7/src/license.h"
#endif
/*
* Copyright (c) 2013-2014 Cesanta Software Limited
* All rights reserved
*
* This software is dual-licensed: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. For the terms of this
* license, see <http://www.gnu.org/licenses/>.
*
* You are free to use this software under the terms of the GNU General
* Public License, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* Alternatively, you can license this software under a commercial
* license, as set out in <https://www.cesanta.com/license>.
*/
#ifdef V7_EXPOSE_PRIVATE
#define V7_PRIVATE
#define V7_EXTERN extern
#else
#define V7_PRIVATE static
#define V7_EXTERN static
#endif /* CS_V7_SRC_LICENSE_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/features_profiles.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_V7_SRC_FEATURES_PROFILES_H_
#define CS_V7_SRC_FEATURES_PROFILES_H_
#define V7_BUILD_PROFILE_MINIMAL 1
#define V7_BUILD_PROFILE_MEDIUM 2
#define V7_BUILD_PROFILE_FULL 3
#ifndef V7_BUILD_PROFILE
#define V7_BUILD_PROFILE V7_BUILD_PROFILE_FULL
#endif
#endif /* CS_V7_SRC_FEATURES_PROFILES_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/features_minimal.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/* Amalgamated: #include "v7/src/features_profiles.h" */
#if V7_BUILD_PROFILE == V7_BUILD_PROFILE_MINIMAL
/* This space is intentionally left blank. */
#endif /* CS_V7_SRC_FEATURES_MINIMAL_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/features_medium.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/* Amalgamated: #include "v7/src/features_profiles.h" */
#if V7_BUILD_PROFILE == V7_BUILD_PROFILE_MEDIUM
#define V7_ENABLE__Date 1
#define V7_ENABLE__Date__now 1
#define V7_ENABLE__Date__UTC 1
#define V7_ENABLE__Math 1
#define V7_ENABLE__Math__atan2 1
#define V7_ENABLE__RegExp 1
#endif /* CS_V7_SRC_FEATURES_MEDIUM_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/features_full.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_V7_SRC_FEATURES_FULL_H_
#define CS_V7_SRC_FEATURES_FULL_H_
/* Amalgamated: #include "v7/src/features_profiles.h" */
#if V7_BUILD_PROFILE == V7_BUILD_PROFILE_FULL
/*
* DO NOT EDIT.
* This file is generated by scripts/gen-features-full.pl.
*/
#ifndef CS_ENABLE_UTF8 /* ifdef-ok */
#define CS_ENABLE_UTF8 1
#endif
#define V7_ENABLE__Array__reduce 1
#define V7_ENABLE__Blob 1
#define V7_ENABLE__Date 1
#define V7_ENABLE__Date__UTC 1
#define V7_ENABLE__Date__getters 1
#define V7_ENABLE__Date__now 1
#define V7_ENABLE__Date__parse 1
#define V7_ENABLE__Date__setters 1
#define V7_ENABLE__Date__toJSON 1
#define V7_ENABLE__Date__toLocaleString 1
#define V7_ENABLE__Date__toString 1
#define V7_ENABLE__File__list 1
#define V7_ENABLE__File__require 1
#define V7_ENABLE__Function__bind 1
#define V7_ENABLE__Function__call 1
#define V7_ENABLE__Math 1
#define V7_ENABLE__Math__abs 1
#define V7_ENABLE__Math__acos 1
#define V7_ENABLE__Math__asin 1
#define V7_ENABLE__Math__atan 1
#define V7_ENABLE__Math__atan2 1
#define V7_ENABLE__Math__ceil 1
#define V7_ENABLE__Math__constants 1
#define V7_ENABLE__Math__cos 1
#define V7_ENABLE__Math__exp 1
#define V7_ENABLE__Math__floor 1
#define V7_ENABLE__Math__log 1
#define V7_ENABLE__Math__max 1
#define V7_ENABLE__Math__min 1
#define V7_ENABLE__Math__pow 1
#define V7_ENABLE__Math__random 1
#define V7_ENABLE__Math__round 1
#define V7_ENABLE__Math__sin 1
#define V7_ENABLE__Math__sqrt 1
#define V7_ENABLE__Math__tan 1
#define V7_ENABLE__Memory__stats 1
#define V7_ENABLE__NUMBER__NEGATIVE_INFINITY 1
#define V7_ENABLE__NUMBER__POSITIVE_INFINITY 1
#define V7_ENABLE__Object__create 1
#define V7_ENABLE__Object__defineProperties 1
#define V7_ENABLE__Object__getOwnPropertyDescriptor 1
#define V7_ENABLE__Object__getOwnPropertyNames 1
#define V7_ENABLE__Object__getPrototypeOf 1
#define V7_ENABLE__Object__hasOwnProperty 1
#define V7_ENABLE__Object__isExtensible 1
#define V7_ENABLE__Object__isFrozen 1
#define V7_ENABLE__Object__isPrototypeOf 1
#define V7_ENABLE__Object__isSealed 1
#define V7_ENABLE__Object__keys 1
#define V7_ENABLE__Object__preventExtensions 1
#define V7_ENABLE__Object__propertyIsEnumerable 1
#define V7_ENABLE__Proxy 1
#define V7_ENABLE__RegExp 1
#define V7_ENABLE__StackTrace 1
#define V7_ENABLE__String__localeCompare 1
#define V7_ENABLE__String__localeLowerCase 1
#define V7_ENABLE__String__localeUpperCase 1
#endif /* V7_BUILD_PROFILE == V7_BUILD_PROFILE_FULL */
#endif /* CS_V7_SRC_FEATURES_FULL_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/features_all.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_V7_SRC_FEATURES_ALL_H_
#define CS_V7_SRC_FEATURES_ALL_H_
/*
* DO NOT EDIT.
* This file is generated by scripts/gen-features-all.pl.
*/
#ifndef V7_ENABLE__Array__reduce
#define V7_ENABLE__Array__reduce 0
#endif
#ifndef V7_ENABLE__Blob
#define V7_ENABLE__Blob 0
#endif
#ifndef V7_ENABLE__Date
#define V7_ENABLE__Date 0
#endif
#ifndef V7_ENABLE__Date__UTC
#define V7_ENABLE__Date__UTC 0
#endif
#ifndef V7_ENABLE__Date__getters
#define V7_ENABLE__Date__getters 0
#endif
#ifndef V7_ENABLE__Date__now
#define V7_ENABLE__Date__now 0
#endif
#ifndef V7_ENABLE__Date__parse
#define V7_ENABLE__Date__parse 0
#endif
#ifndef V7_ENABLE__Date__setters
#define V7_ENABLE__Date__setters 0
#endif
#ifndef V7_ENABLE__Date__toJSON
#define V7_ENABLE__Date__toJSON 0
#endif
#ifndef V7_ENABLE__Date__toLocaleString
#define V7_ENABLE__Date__toLocaleString 0
#endif
#ifndef V7_ENABLE__Date__toString
#define V7_ENABLE__Date__toString 0
#endif
#ifndef V7_ENABLE__File__list
#define V7_ENABLE__File__list 0
#endif
#ifndef V7_ENABLE__File__require
#define V7_ENABLE__File__require 0
#endif
#ifndef V7_ENABLE__Function__bind
#define V7_ENABLE__Function__bind 0
#endif
#ifndef V7_ENABLE__Function__call
#define V7_ENABLE__Function__call 0
#endif
#ifndef V7_ENABLE__Math
#define V7_ENABLE__Math 0
#endif
#ifndef V7_ENABLE__Math__abs
#define V7_ENABLE__Math__abs 0
#endif
#ifndef V7_ENABLE__Math__acos
#define V7_ENABLE__Math__acos 0
#endif
#ifndef V7_ENABLE__Math__asin
#define V7_ENABLE__Math__asin 0
#endif
#ifndef V7_ENABLE__Math__atan
#define V7_ENABLE__Math__atan 0
#endif
#ifndef V7_ENABLE__Math__atan2
#define V7_ENABLE__Math__atan2 0
#endif
#ifndef V7_ENABLE__Math__ceil
#define V7_ENABLE__Math__ceil 0
#endif
#ifndef V7_ENABLE__Math__constants
#define V7_ENABLE__Math__constants 0
#endif
#ifndef V7_ENABLE__Math__cos
#define V7_ENABLE__Math__cos 0
#endif
#ifndef V7_ENABLE__Math__exp
#define V7_ENABLE__Math__exp 0
#endif
#ifndef V7_ENABLE__Math__floor
#define V7_ENABLE__Math__floor 0
#endif
#ifndef V7_ENABLE__Math__log
#define V7_ENABLE__Math__log 0
#endif
#ifndef V7_ENABLE__Math__max
#define V7_ENABLE__Math__max 0
#endif
#ifndef V7_ENABLE__Math__min
#define V7_ENABLE__Math__min 0
#endif
#ifndef V7_ENABLE__Math__pow
#define V7_ENABLE__Math__pow 0
#endif
#ifndef V7_ENABLE__Math__random
#define V7_ENABLE__Math__random 0
#endif
#ifndef V7_ENABLE__Math__round
#define V7_ENABLE__Math__round 0
#endif
#ifndef V7_ENABLE__Math__sin
#define V7_ENABLE__Math__sin 0
#endif
#ifndef V7_ENABLE__Math__sqrt
#define V7_ENABLE__Math__sqrt 0
#endif
#ifndef V7_ENABLE__Math__tan
#define V7_ENABLE__Math__tan 0
#endif
#ifndef V7_ENABLE__Memory__stats
#define V7_ENABLE__Memory__stats 0
#endif
#ifndef V7_ENABLE__NUMBER__NEGATIVE_INFINITY
#define V7_ENABLE__NUMBER__NEGATIVE_INFINITY 0
#endif
#ifndef V7_ENABLE__NUMBER__POSITIVE_INFINITY
#define V7_ENABLE__NUMBER__POSITIVE_INFINITY 0
#endif
#ifndef V7_ENABLE__Object__create
#define V7_ENABLE__Object__create 0
#endif
#ifndef V7_ENABLE__Object__defineProperties
#define V7_ENABLE__Object__defineProperties 0
#endif
#ifndef V7_ENABLE__Object__getOwnPropertyDescriptor
#define V7_ENABLE__Object__getOwnPropertyDescriptor 0
#endif
#ifndef V7_ENABLE__Object__getOwnPropertyNames
#define V7_ENABLE__Object__getOwnPropertyNames 0
#endif
#ifndef V7_ENABLE__Object__getPrototypeOf
#define V7_ENABLE__Object__getPrototypeOf 0
#endif
#ifndef V7_ENABLE__Object__hasOwnProperty
#define V7_ENABLE__Object__hasOwnProperty 0
#endif
#ifndef V7_ENABLE__Object__isExtensible
#define V7_ENABLE__Object__isExtensible 0
#endif
#ifndef V7_ENABLE__Object__isFrozen
#define V7_ENABLE__Object__isFrozen 0
#endif
#ifndef V7_ENABLE__Object__isPrototypeOf
#define V7_ENABLE__Object__isPrototypeOf 0
#endif
#ifndef V7_ENABLE__Object__isSealed
#define V7_ENABLE__Object__isSealed 0
#endif
#ifndef V7_ENABLE__Object__keys
#define V7_ENABLE__Object__keys 0
#endif
#ifndef V7_ENABLE__Object__preventExtensions
#define V7_ENABLE__Object__preventExtensions 0
#endif
#ifndef V7_ENABLE__Object__propertyIsEnumerable
#define V7_ENABLE__Object__propertyIsEnumerable 0
#endif
#ifndef V7_ENABLE__Proxy
#define V7_ENABLE__Proxy 0
#endif
#ifndef V7_ENABLE__RegExp
#define V7_ENABLE__RegExp 0
#endif
#ifndef V7_ENABLE__StackTrace
#define V7_ENABLE__StackTrace 0
#endif
#ifndef V7_ENABLE__String__localeCompare
#define V7_ENABLE__String__localeCompare 0
#endif
#ifndef V7_ENABLE__String__localeLowerCase
#define V7_ENABLE__String__localeLowerCase 0
#endif
#ifndef V7_ENABLE__String__localeUpperCase
#define V7_ENABLE__String__localeUpperCase 0
#endif
#endif /* CS_V7_SRC_FEATURES_ALL_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/v7_features.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_V7_SRC_V7_FEATURES_H_
#define CS_V7_SRC_V7_FEATURES_H_
/* Only one will actually be used based on V7_BUILD_PROFILE. */
/* Amalgamated: #include "v7/src/features_minimal.h" */
/* Amalgamated: #include "v7/src/features_medium.h" */
/* Amalgamated: #include "v7/src/features_full.h" */
/* All the features will be default-defined to 0. */
/* Amalgamated: #include "v7/src/features_all.h" */
#ifndef V7_DISABLE_AST_TAG_NAMES
#define V7_DISABLE_AST_TAG_NAMES 0
#endif
#ifndef V7_DISABLE_GC
#define V7_DISABLE_GC 0
#endif
#ifndef V7_DISABLE_CALL_ERROR_CONTEXT
#define V7_DISABLE_CALL_ERROR_CONTEXT 0
#endif
#ifndef V7_DISABLE_FILENAMES
#define V7_DISABLE_FILENAMES 0
#endif
#ifndef V7_DISABLE_LINE_NUMBERS
#define V7_DISABLE_LINE_NUMBERS 0
#endif
#ifndef V7_DISABLE_STR_ALLOC_SEQ
#define V7_DISABLE_STR_ALLOC_SEQ 0
#endif
#ifndef V7_ENABLE_CALL_TRACE
#define V7_ENABLE_CALL_TRACE 0
#endif
#ifndef V7_ENABLE_CRYPTO
#define V7_ENABLE_CRYPTO 0
#endif
#ifndef V7_ENABLE_DENSE_ARRAYS
#define V7_ENABLE_DENSE_ARRAYS 0
#endif
#ifndef V7_ENABLE_ENTITY_IDS
#define V7_ENABLE_ENTITY_IDS 0
#endif
#ifndef V7_ENABLE_FILE
#define V7_ENABLE_FILE 0
#endif
#ifndef V7_ENABLE_FOOTPRINT_REPORT
#define V7_ENABLE_FOOTPRINT_REPORT 0
#endif
#ifndef V7_ENABLE_GC_CHECK
#define V7_ENABLE_GC_CHECK 0
#endif
#ifndef V7_ENABLE_JS_GETTERS
#define V7_ENABLE_JS_GETTERS 0
#endif
#ifndef V7_ENABLE_JS_SETTERS
#define V7_ENABLE_JS_SETTERS 0
#endif
#ifndef V7_ENABLE_STACK_TRACKING
#define V7_ENABLE_STACK_TRACKING 0
#endif
#ifndef V7_ENABLE_SOCKET
#define V7_ENABLE_SOCKET 0
#endif
#ifndef V7_AST_FORCE_LINE_NUMBERS
#define V7_AST_FORCE_LINE_NUMBERS 0
#endif
#ifndef V7_HEAPUSAGE_ENABLE
#define V7_HEAPUSAGE_ENABLE 0
#endif
#endif /* CS_V7_SRC_V7_FEATURES_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/platform.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_V7_SRC_PLATFORM_H_
#define CS_V7_SRC_PLATFORM_H_
#ifdef __arm
#undef V7_ENABLE__Date
#define V7_ENABLE__Date 0
#endif
#endif /* CS_V7_SRC_PLATFORM_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/core_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Core
*/
#ifndef CS_V7_SRC_CORE_PUBLIC_H_
#define CS_V7_SRC_CORE_PUBLIC_H_
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
/* Amalgamated: #include "v7/src/license.h" */
/* Amalgamated: #include "v7/src/v7_features.h" */
/* Amalgamated: #include "v7/src/platform.h" */
#include <stddef.h> /* For size_t */
#include <stdio.h> /* For FILE */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*
* TODO(dfrank) : improve amalgamation, so that we'll be able to include
* files here, and include common/platform.h
*
* For now, copy-pasting `WARN_UNUSED_RESULT` here
*/
#ifdef __GNUC__
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#define NOINSTR __attribute__((no_instrument_function))
#else
#define WARN_UNUSED_RESULT
#define NOINSTR
#endif
#define V7_VERSION "1.0"
#if (defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__)) || \
(defined(_MSC_VER) && _MSC_VER <= 1200)
#define V7_WINDOWS
#endif
#ifdef V7_WINDOWS
typedef unsigned __int64 uint64_t;
#else
#include <inttypes.h>
#endif
/* 64-bit value, used to store JS values */
typedef uint64_t v7_val_t;
/* JavaScript `null` value */
#define V7_NULL ((uint64_t) 0xfffe << 48)
/* JavaScript `undefined` value */
#define V7_UNDEFINED ((uint64_t) 0xfffd << 48)
/* This if-0 is a dirty workaround to force etags to pick `struct v7` */
#if 0
/* Opaque structure. V7 engine context. */
struct v7 {
/* ... */
};
#endif
struct v7;
/*
* Code which is returned by some of the v7 functions. If something other than
* `V7_OK` is returned from some function, the caller function typically should
* either immediately cleanup and return the code further, or handle the error.
*/
enum v7_err {
V7_OK,
V7_SYNTAX_ERROR,
V7_EXEC_EXCEPTION,
V7_AST_TOO_LARGE,
V7_INTERNAL_ERROR,
};
/* JavaScript -> C call interface */
WARN_UNUSED_RESULT
typedef enum v7_err(v7_cfunction_t)(struct v7 *v7, v7_val_t *res);
/* Create V7 instance */
struct v7 *v7_create(void);
/*
* Customizations of initial V7 state; used by `v7_create_opt()`.
*/
struct v7_create_opts {
size_t object_arena_size;
size_t function_arena_size;
size_t property_arena_size;
#ifdef V7_STACK_SIZE
void *c_stack_base;
#endif
#ifdef V7_FREEZE
/* if not NULL, dump JS heap after init */
char *freeze_file;
#endif
};
/*
* Like `v7_create()`, but allows to customize initial v7 state, see `struct
* v7_create_opts`.
*/
struct v7 *v7_create_opt(struct v7_create_opts opts);
/* Destroy V7 instance */
void v7_destroy(struct v7 *v7);
/* Return root level (`global`) object of the given V7 instance. */
v7_val_t v7_get_global(struct v7 *v);
/* Return current `this` object. */
v7_val_t v7_get_this(struct v7 *v);
/* Return current `arguments` array */
v7_val_t v7_get_arguments(struct v7 *v);
/* Return i-th argument */
v7_val_t v7_arg(struct v7 *v, unsigned long i);
/* Return the length of `arguments` */
unsigned long v7_argc(struct v7 *v7);
/*
* Tells the GC about a JS value variable/field owned
* by C code.
*
* User C code should own v7_val_t variables
* if the value's lifetime crosses any invocation
* to the v7 runtime that creates new objects or new
* properties and thus can potentially trigger GC.
*
* The registration of the variable prevents the GC from mistakenly treat
* the object as garbage. The GC might be triggered potentially
* allows the GC to update pointers
*
* User code should also explicitly disown the variables with v7_disown once
* it goes out of scope or the structure containing the v7_val_t field is freed.
*
* Example:
*
* ```
* struct v7_val cb;
* v7_own(v7, &cb);
* cb = v7_array_get(v7, args, 0);
* // do something with cb
* v7_disown(v7, &cb);
* ```
*/
void v7_own(struct v7 *v7, v7_val_t *v);
/*
* Returns 1 if value is found, 0 otherwise
*/
int v7_disown(struct v7 *v7, v7_val_t *v);
/*
* Enable or disable GC.
*
* Must be called before invoking v7_exec or v7_apply
* from within a cfunction unless you know what you're doing.
*
* GC is disabled during execution of cfunctions in order to simplify
* memory management of simple cfunctions.
* However executing even small snippets of JS code causes a lot of memory
* pressure. Enabling GC solves that but forces you to take care of the
* reachability of your temporary V7 v7_val_t variables, as the GC needs
* to know where they are since objects and strings can be either reclaimed
* or relocated during a GC pass.
*/
void v7_set_gc_enabled(struct v7 *v7, int enabled);
/*
* Set an optional C stack limit.
*
* It sets a flag that will cause the interpreter
* to throw an InterruptedError.
* It's safe to call it from signal handlers and ISRs
* on single threaded environments.
*/
void v7_interrupt(struct v7 *v7);
/* Returns last parser error message. TODO: rename it to `v7_get_error()` */
const char *v7_get_parser_error(struct v7 *v7);
#if V7_ENABLE_STACK_TRACKING
/*
* Available if only `V7_ENABLE_STACK_TRACKING` is defined.
*
* Stack metric id. See `v7_stack_stat()`
*/
enum v7_stack_stat_what {
/* max stack size consumed by `i_exec()` */
V7_STACK_STAT_EXEC,
/* max stack size consumed by `parse()` (which is called from `i_exec()`) */
V7_STACK_STAT_PARSER,
V7_STACK_STATS_CNT
};
/*
* Available if only `V7_ENABLE_STACK_TRACKING` is defined.
*
* Returns stack metric specified by the metric id `what`. See
* `v7_stack_stat_clean()`
*/
int v7_stack_stat(struct v7 *v7, enum v7_stack_stat_what what);
/*
* Available if only `V7_ENABLE_STACK_TRACKING` is defined.
*
* Clean all stack statistics gathered so far. See `v7_stack_stat()`
*/
void v7_stack_stat_clean(struct v7 *v7);
#endif
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_CORE_PUBLIC_H_ */
#ifndef V7_EXPORT_INTERNAL_HEADERS
#ifdef V7_MODULE_LINES
#line 1 "v7/src/core_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Core
*/
#ifndef CS_V7_SRC_CORE_PUBLIC_H_
#define CS_V7_SRC_CORE_PUBLIC_H_
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
/* Amalgamated: #include "v7/src/license.h" */
/* Amalgamated: #include "v7/src/v7_features.h" */
/* Amalgamated: #include "v7/src/platform.h" */
#include <stddef.h> /* For size_t */
#include <stdio.h> /* For FILE */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*
* TODO(dfrank) : improve amalgamation, so that we'll be able to include
* files here, and include common/platform.h
*
* For now, copy-pasting `WARN_UNUSED_RESULT` here
*/
#ifdef __GNUC__
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#define NOINSTR __attribute__((no_instrument_function))
#else
#define WARN_UNUSED_RESULT
#define NOINSTR
#endif
#define V7_VERSION "1.0"
#if (defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__)) || \
(defined(_MSC_VER) && _MSC_VER <= 1200)
#define V7_WINDOWS
#endif
#ifdef V7_WINDOWS
typedef unsigned __int64 uint64_t;
#else
#include <inttypes.h>
#endif
/* 64-bit value, used to store JS values */
typedef uint64_t v7_val_t;
/* JavaScript `null` value */
#define V7_NULL ((uint64_t) 0xfffe << 48)
/* JavaScript `undefined` value */
#define V7_UNDEFINED ((uint64_t) 0xfffd << 48)
/* This if-0 is a dirty workaround to force etags to pick `struct v7` */
#if 0
/* Opaque structure. V7 engine context. */
struct v7 {
/* ... */
};
#endif
struct v7;
/*
* Code which is returned by some of the v7 functions. If something other than
* `V7_OK` is returned from some function, the caller function typically should
* either immediately cleanup and return the code further, or handle the error.
*/
enum v7_err {
V7_OK,
V7_SYNTAX_ERROR,
V7_EXEC_EXCEPTION,
V7_AST_TOO_LARGE,
V7_INTERNAL_ERROR,
};
/* JavaScript -> C call interface */
WARN_UNUSED_RESULT
typedef enum v7_err(v7_cfunction_t)(struct v7 *v7, v7_val_t *res);
/* Create V7 instance */
struct v7 *v7_create(void);
/*
* Customizations of initial V7 state; used by `v7_create_opt()`.
*/
struct v7_create_opts {
size_t object_arena_size;
size_t function_arena_size;
size_t property_arena_size;
#ifdef V7_STACK_SIZE
void *c_stack_base;
#endif
#ifdef V7_FREEZE
/* if not NULL, dump JS heap after init */
char *freeze_file;
#endif
};
/*
* Like `v7_create()`, but allows to customize initial v7 state, see `struct
* v7_create_opts`.
*/
struct v7 *v7_create_opt(struct v7_create_opts opts);
/* Destroy V7 instance */
void v7_destroy(struct v7 *v7);
/* Return root level (`global`) object of the given V7 instance. */
v7_val_t v7_get_global(struct v7 *v);
/* Return current `this` object. */
v7_val_t v7_get_this(struct v7 *v);
/* Return current `arguments` array */
v7_val_t v7_get_arguments(struct v7 *v);
/* Return i-th argument */
v7_val_t v7_arg(struct v7 *v, unsigned long i);
/* Return the length of `arguments` */
unsigned long v7_argc(struct v7 *v7);
/*
* Tells the GC about a JS value variable/field owned
* by C code.
*
* User C code should own v7_val_t variables
* if the value's lifetime crosses any invocation
* to the v7 runtime that creates new objects or new
* properties and thus can potentially trigger GC.
*
* The registration of the variable prevents the GC from mistakenly treat
* the object as garbage. The GC might be triggered potentially
* allows the GC to update pointers
*
* User code should also explicitly disown the variables with v7_disown once
* it goes out of scope or the structure containing the v7_val_t field is freed.
*
* Example:
*
* ```
* struct v7_val cb;
* v7_own(v7, &cb);
* cb = v7_array_get(v7, args, 0);
* // do something with cb
* v7_disown(v7, &cb);
* ```
*/
void v7_own(struct v7 *v7, v7_val_t *v);
/*
* Returns 1 if value is found, 0 otherwise
*/
int v7_disown(struct v7 *v7, v7_val_t *v);
/*
* Enable or disable GC.
*
* Must be called before invoking v7_exec or v7_apply
* from within a cfunction unless you know what you're doing.
*
* GC is disabled during execution of cfunctions in order to simplify
* memory management of simple cfunctions.
* However executing even small snippets of JS code causes a lot of memory
* pressure. Enabling GC solves that but forces you to take care of the
* reachability of your temporary V7 v7_val_t variables, as the GC needs
* to know where they are since objects and strings can be either reclaimed
* or relocated during a GC pass.
*/
void v7_set_gc_enabled(struct v7 *v7, int enabled);
/*
* Set an optional C stack limit.
*
* It sets a flag that will cause the interpreter
* to throw an InterruptedError.
* It's safe to call it from signal handlers and ISRs
* on single threaded environments.
*/
void v7_interrupt(struct v7 *v7);
/* Returns last parser error message. TODO: rename it to `v7_get_error()` */
const char *v7_get_parser_error(struct v7 *v7);
#if V7_ENABLE_STACK_TRACKING
/*
* Available if only `V7_ENABLE_STACK_TRACKING` is defined.
*
* Stack metric id. See `v7_stack_stat()`
*/
enum v7_stack_stat_what {
/* max stack size consumed by `i_exec()` */
V7_STACK_STAT_EXEC,
/* max stack size consumed by `parse()` (which is called from `i_exec()`) */
V7_STACK_STAT_PARSER,
V7_STACK_STATS_CNT
};
/*
* Available if only `V7_ENABLE_STACK_TRACKING` is defined.
*
* Returns stack metric specified by the metric id `what`. See
* `v7_stack_stat_clean()`
*/
int v7_stack_stat(struct v7 *v7, enum v7_stack_stat_what what);
/*
* Available if only `V7_ENABLE_STACK_TRACKING` is defined.
*
* Clean all stack statistics gathered so far. See `v7_stack_stat()`
*/
void v7_stack_stat_clean(struct v7 *v7);
#endif
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_CORE_PUBLIC_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/primitive_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Primitives
*
* All primitive values but strings.
*
* "foreign" values are also here, see `v7_mk_foreign()`.
*/
#ifndef CS_V7_SRC_PRIMITIVE_PUBLIC_H_
#define CS_V7_SRC_PRIMITIVE_PUBLIC_H_
/* Amalgamated: #include "v7/src/core_public.h" */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/* Make numeric primitive value */
NOINSTR v7_val_t v7_mk_number(struct v7 *v7, double num);
/*
* Returns number value stored in `v7_val_t` as `double`.
*
* Returns NaN for non-numbers.
*/
NOINSTR double v7_get_double(struct v7 *v7, v7_val_t v);
/*
* Returns number value stored in `v7_val_t` as `int`. If the number value is
* not an integer, the fraction part will be discarded.
*
* If the given value is a non-number, or NaN, the result is undefined.
*/
NOINSTR int v7_get_int(struct v7 *v7, v7_val_t v);
/* Returns true if given value is a primitive number value */
int v7_is_number(v7_val_t v);
/* Make boolean primitive value (either `true` or `false`) */
NOINSTR v7_val_t v7_mk_boolean(struct v7 *v7, int is_true);
/*
* Returns boolean stored in `v7_val_t`:
* 0 for `false` or non-boolean, non-0 for `true`
*/
NOINSTR int v7_get_bool(struct v7 *v7, v7_val_t v);
/* Returns true if given value is a primitive boolean value */
int v7_is_boolean(v7_val_t v);
/*
* Make `null` primitive value.
*
* NOTE: this function is deprecated and will be removed in future releases.
* Use `V7_NULL` instead.
*/
NOINSTR v7_val_t v7_mk_null(void);
/* Returns true if given value is a primitive `null` value */
int v7_is_null(v7_val_t v);
/*
* Make `undefined` primitive value.
*
* NOTE: this function is deprecated and will be removed in future releases.
* Use `V7_UNDEFINED` instead.
*/
NOINSTR v7_val_t v7_mk_undefined(void);
/* Returns true if given value is a primitive `undefined` value */
int v7_is_undefined(v7_val_t v);
/*
* Make JavaScript value that holds C/C++ `void *` pointer.
*
* A foreign value is completely opaque and JS code cannot do anything useful
* with it except holding it in properties and passing it around.
* It behaves like a sealed object with no properties.
*
* NOTE:
* Only valid pointers (as defined by each supported architecture) will fully
* preserved. In particular, all supported 64-bit architectures (x86_64, ARM-64)
* actually define a 48-bit virtual address space.
* Foreign values will be sign-extended as required, i.e creating a foreign
* value of something like `(void *) -1` will work as expected. This is
* important because in some 64-bit OSs (e.g. Solaris) the user stack grows
* downwards from the end of the address space.
*
* If you need to store exactly sizeof(void*) bytes of raw data where
* `sizeof(void*)` >= 8, please use byte arrays instead.
*/
NOINSTR v7_val_t v7_mk_foreign(struct v7 *v7, void *ptr);
/*
* Returns `void *` pointer stored in `v7_val_t`.
*
* Returns NULL if the value is not a foreign pointer.
*/
NOINSTR void *v7_get_ptr(struct v7 *v7, v7_val_t v);
/* Returns true if given value holds `void *` pointer */
int v7_is_foreign(v7_val_t v);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_PRIMITIVE_PUBLIC_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/string_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Strings
*/
#ifndef CS_V7_SRC_STRING_PUBLIC_H_
#define CS_V7_SRC_STRING_PUBLIC_H_
/* Amalgamated: #include "v7/src/core_public.h" */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*
* Creates a string primitive value.
* `str` must point to the utf8 string of length `len`.
* If `len` is ~0, `str` is assumed to be NUL-terminated and `strlen(str)` is
* used.
*
* If `copy` is non-zero, the string data is copied and owned by the GC. The
* caller can free the string data afterwards. Otherwise (`copy` is zero), the
* caller owns the string data, and is responsible for not freeing it while it
* is used.
*/
v7_val_t v7_mk_string(struct v7 *v7, const char *str, size_t len, int copy);
/* Returns true if given value is a primitive string value */
int v7_is_string(v7_val_t v);
/*
* Returns a pointer to the string stored in `v7_val_t`.
*
* String length returned in `len`, which is allowed to be NULL. Returns NULL
* if the value is not a string.
*
* JS strings can contain embedded NUL chars and may or may not be NUL
* terminated.
*
* CAUTION: creating new JavaScript object, array, or string may kick in a
* garbage collector, which in turn may relocate string data and invalidate
* pointer returned by `v7_get_string()`.
*
* Short JS strings are embedded inside the `v7_val_t` value itself. This is why
* a pointer to a `v7_val_t` is required. It also means that the string data
* will become invalid once that `v7_val_t` value goes out of scope.
*/
const char *v7_get_string(struct v7 *v7, v7_val_t *v, size_t *len);
/*
* Returns a pointer to the string stored in `v7_val_t`.
*
* Returns NULL if the value is not a string or if the string is not compatible
* with a C string.
*
* C compatible strings contain exactly one NUL char, in terminal position.
*
* All strings owned by the V7 engine (see `v7_mk_string()`) are guaranteed to
* be NUL terminated. Out of these, those that don't include embedded NUL chars
* are guaranteed to be C compatible.
*/
const char *v7_get_cstring(struct v7 *v7, v7_val_t *v);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_STRING_PUBLIC_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/object_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Objects
*/
#ifndef CS_V7_SRC_OBJECT_PUBLIC_H_
#define CS_V7_SRC_OBJECT_PUBLIC_H_
/* Amalgamated: #include "v7/src/core_public.h" */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*
* Property attributes bitmask
*/
typedef unsigned short v7_prop_attr_t;
#define V7_PROPERTY_NON_WRITABLE (1 << 0)
#define V7_PROPERTY_NON_ENUMERABLE (1 << 1)
#define V7_PROPERTY_NON_CONFIGURABLE (1 << 2)
#define V7_PROPERTY_GETTER (1 << 3)
#define V7_PROPERTY_SETTER (1 << 4)
#define _V7_PROPERTY_HIDDEN (1 << 5)
/* property not managed by V7 HEAP */
#define _V7_PROPERTY_OFF_HEAP (1 << 6)
/* special property holding user data and destructor cb */
#define _V7_PROPERTY_USER_DATA_AND_DESTRUCTOR (1 << 7)
/*
* not a property attribute, but a flag for `v7_def()`. It's here in order to
* keep all offsets in one place
*/
#define _V7_DESC_PRESERVE_VALUE (1 << 8)
#define V7_PROP_ATTR_IS_WRITABLE(a) (!(a & V7_PROPERTY_NON_WRITABLE))
#define V7_PROP_ATTR_IS_ENUMERABLE(a) (!(a & V7_PROPERTY_NON_ENUMERABLE))
#define V7_PROP_ATTR_IS_CONFIGURABLE(a) (!(a & V7_PROPERTY_NON_CONFIGURABLE))
/*
* Internal helpers for `V7_DESC_...` macros
*/
#define _V7_DESC_SHIFT 16
#define _V7_DESC_MASK ((1 << _V7_DESC_SHIFT) - 1)
#define _V7_MK_DESC(v, n) \
(((v7_prop_attr_desc_t)(n)) << _V7_DESC_SHIFT | ((v) ? (n) : 0))
#define _V7_MK_DESC_INV(v, n) _V7_MK_DESC(!(v), (n))
/*
* Property attribute descriptors that may be given to `v7_def()`: for each
* attribute (`v7_prop_attr_t`), there is a corresponding macro, which takes
* param: either 1 (set attribute) or 0 (clear attribute). If some particular
* attribute isn't mentioned at all, it's left unchanged (or default, if the
* property is being created)
*
* There is additional flag: `V7_DESC_PRESERVE_VALUE`. If it is set, the
* property value isn't changed (or set to `undefined` if the property is being
* created)
*/
typedef unsigned long v7_prop_attr_desc_t;
#define V7_DESC_WRITABLE(v) _V7_MK_DESC_INV(v, V7_PROPERTY_NON_WRITABLE)
#define V7_DESC_ENUMERABLE(v) _V7_MK_DESC_INV(v, V7_PROPERTY_NON_ENUMERABLE)
#define V7_DESC_CONFIGURABLE(v) _V7_MK_DESC_INV(v, V7_PROPERTY_NON_CONFIGURABLE)
#define V7_DESC_GETTER(v) _V7_MK_DESC(v, V7_PROPERTY_GETTER)
#define V7_DESC_SETTER(v) _V7_MK_DESC(v, V7_PROPERTY_SETTER)
#define V7_DESC_PRESERVE_VALUE _V7_DESC_PRESERVE_VALUE
#define _V7_DESC_HIDDEN(v) _V7_MK_DESC(v, _V7_PROPERTY_HIDDEN)
#define _V7_DESC_OFF_HEAP(v) _V7_MK_DESC(v, _V7_PROPERTY_OFF_HEAP)
/* See `v7_set_destructor_cb` */
typedef void(v7_destructor_cb_t)(struct v7 *v7, void *ud);
/* Make an empty object */
v7_val_t v7_mk_object(struct v7 *v7);
/*
* Returns true if the given value is an object or function.
* i.e. it returns true if the value holds properties and can be
* used as argument to `v7_get`, `v7_set` and `v7_def`.
*/
int v7_is_object(v7_val_t v);
/* Set object's prototype. Return old prototype or undefined on error. */
v7_val_t v7_set_proto(struct v7 *v7, v7_val_t obj, v7_val_t proto);
/* Get object's prototype. */
v7_val_t v7_get_proto(struct v7 *v7, v7_val_t obj);
/*
* Lookup property `name` in object `obj`. If `obj` holds no such property,
* an `undefined` value is returned.
*
* If `name_len` is ~0, `name` is assumed to be NUL-terminated and
* `strlen(name)` is used.
*/
v7_val_t v7_get(struct v7 *v7, v7_val_t obj, const char *name, size_t name_len);
/*
* Like `v7_get()`, but "returns" value through `res` pointer argument.
* `res` must not be `NULL`.
*
* Caller should check the error code returned, and if it's something other
* than `V7_OK`, perform cleanup and return this code further.
*/
WARN_UNUSED_RESULT
enum v7_err v7_get_throwing(struct v7 *v7, v7_val_t obj, const char *name,
size_t name_len, v7_val_t *res);
/*
* Define object property, similar to JavaScript `Object.defineProperty()`.
*
* `name`, `name_len` specify property name, `val` is a property value.
* `attrs_desc` is a set of flags which can affect property's attributes,
* see comment of `v7_prop_attr_desc_t` for details.
*
* If `name_len` is ~0, `name` is assumed to be NUL-terminated and
* `strlen(name)` is used.
*
* Returns non-zero on success, 0 on error (e.g. out of memory).
*
* See also `v7_set()`.
*/
int v7_def(struct v7 *v7, v7_val_t obj, const char *name, size_t name_len,
v7_prop_attr_desc_t attrs_desc, v7_val_t v);
/*
* Set object property. Behaves just like JavaScript assignment.
*
* See also `v7_def()`.
*/
int v7_set(struct v7 *v7, v7_val_t obj, const char *name, size_t len,
v7_val_t val);
/*
* A helper function to define object's method backed by a C function `func`.
* `name` must be NUL-terminated.
*
* Return value is the same as for `v7_set()`.
*/
int v7_set_method(struct v7 *, v7_val_t obj, const char *name,
v7_cfunction_t *func);
/*
* Delete own property `name` of the object `obj`. Does not follow the
* prototype chain.
*
* If `name_len` is ~0, `name` is assumed to be NUL-terminated and
* `strlen(name)` is used.
*
* Returns 0 on success, -1 on error.
*/
int v7_del(struct v7 *v7, v7_val_t obj, const char *name, size_t name_len);
#if V7_ENABLE__Proxy
struct prop_iter_proxy_ctx;
#endif
/*
* Context for property iteration, see `v7_next_prop()`.
*
* Clients should not interpret contents of this structure, it's here merely to
* allow clients to allocate it not from the heap.
*/
struct prop_iter_ctx {
#if V7_ENABLE__Proxy
struct prop_iter_proxy_ctx *proxy_ctx;
#endif
struct v7_property *cur_prop;
unsigned init : 1;
};
/*
* Initialize the property iteration context `ctx`, see `v7_next_prop()` for
* usage example.
*/
enum v7_err v7_init_prop_iter_ctx(struct v7 *v7, v7_val_t obj,
struct prop_iter_ctx *ctx);
/*
* Destruct the property iteration context `ctx`, see `v7_next_prop()` for
* usage example
*/
void v7_destruct_prop_iter_ctx(struct v7 *v7, struct prop_iter_ctx *ctx);
/*
* Iterate over the `obj`'s properties.
*
* Usage example (here we assume we have some `v7_val_t obj`):
*
* struct prop_iter_ctx ctx;
* v7_val_t name, val;
* v7_prop_attr_t attrs;
*
* v7_init_prop_iter_ctx(v7, obj, &ctx);
* while (v7_next_prop(v7, &ctx, &name, &val, &attrs)) {
* if (V7_PROP_ATTR_IS_ENUMERABLE(attrs)) continue;
* ...
* }
* v7_destruct_prop_iter_ctx(v7, &ctx);
*
* As you see, v7_next_prop will iterate through all properties, including
* non-enumerable ones, and it's your responsibility to test the attributes
* with the provided `V7_PROP_ATTR_*` macros and proceed as you see fit.
*/
int v7_next_prop(struct v7 *v7, struct prop_iter_ctx *ctx, v7_val_t *name,
v7_val_t *value, v7_prop_attr_t *attrs);
/* Returns true if the object is an instance of a given constructor. */
int v7_is_instanceof(struct v7 *v7, v7_val_t o, const char *c);
/* Returns true if the object is an instance of a given constructor. */
int v7_is_instanceof_v(struct v7 *v7, v7_val_t o, v7_val_t c);
/*
* Associates an opaque C value (anything that can be casted to a `void * )
* with an object.
*
* You can achieve a similar effect by just setting a special property with
* a foreign value (see `v7_mk_foreign`), except user data offers the following
* advantages:
*
* 1. You don't have to come up with some arbitrary "special" property name.
* 2. JS scripts cannot access user data by mistake via property lookup.
* 3. The user data is available to the destructor. When the desctructor is
* invoked you cannot access any of its properties.
* 4. Allows the implementation to use a more compact encoding
*
* Does nothing if `obj` is not a mutable object.
*/
void v7_set_user_data(struct v7 *v7, v7_val_t obj, void *ud);
/*
* Get the opaque user data set with `v7_set_user_data`.
*
* Returns NULL if there is no user data set or if `obj` is not an object.
*/
void *v7_get_user_data(struct v7 *v7, v7_val_t obj);
/*
* Register a callback which will be invoked when a given object gets
* reclaimed by the garbage collector.
*
* The callback will be invoked while garbage collection is still in progress
* and hence the internal state of the JS heap is in an undefined state.
*
* The only v7 API which is safe to use in this callback is `v7_disown()`,
* that's why `v7` pointer is given to it. *Calls to any other v7 functions are
* illegal here*.
*
* The intended use case is to reclaim resources allocated by C code.
*/
void v7_set_destructor_cb(struct v7 *v7, v7_val_t obj, v7_destructor_cb_t *d);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_OBJECT_PUBLIC_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/array_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Arrays
*/
#ifndef CS_V7_SRC_ARRAY_PUBLIC_H_
#define CS_V7_SRC_ARRAY_PUBLIC_H_
/* Amalgamated: #include "v7/src/core_public.h" */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/* Make an empty array object */
v7_val_t v7_mk_array(struct v7 *v7);
/* Returns true if given value is an array object */
int v7_is_array(struct v7 *v7, v7_val_t v);
/* Returns length on an array. If `arr` is not an array, 0 is returned. */
unsigned long v7_array_length(struct v7 *v7, v7_val_t arr);
/* Insert value `v` in array `arr` at the end of the array. */
int v7_array_push(struct v7 *, v7_val_t arr, v7_val_t v);
/*
* Like `v7_array_push()`, but "returns" value through the `res` pointer
* argument. `res` is allowed to be `NULL`.
*
* Caller should check the error code returned, and if it's something other
* than `V7_OK`, perform cleanup and return this code further.
*/
WARN_UNUSED_RESULT
enum v7_err v7_array_push_throwing(struct v7 *v7, v7_val_t arr, v7_val_t v,
int *res);
/*
* Return array member at index `index`. If `index` is out of bounds, undefined
* is returned.
*/
v7_val_t v7_array_get(struct v7 *, v7_val_t arr, unsigned long index);
/* Insert value `v` into `arr` at index `index`. */
int v7_array_set(struct v7 *v7, v7_val_t arr, unsigned long index, v7_val_t v);
/*
* Like `v7_array_set()`, but "returns" value through the `res` pointer
* argument. `res` is allowed to be `NULL`.
*
* Caller should check the error code returned, and if it's something other
* than `V7_OK`, perform cleanup and return this code further.
*/
WARN_UNUSED_RESULT
enum v7_err v7_array_set_throwing(struct v7 *v7, v7_val_t arr,
unsigned long index, v7_val_t v, int *res);
/* Delete value in array `arr` at index `index`, if it exists. */
void v7_array_del(struct v7 *v7, v7_val_t arr, unsigned long index);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_ARRAY_PUBLIC_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/function_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Functions
*/
#ifndef CS_V7_SRC_FUNCTION_PUBLIC_H_
#define CS_V7_SRC_FUNCTION_PUBLIC_H_
/* Amalgamated: #include "v7/src/core_public.h" */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*
* Make a JS function object backed by a cfunction.
*
* `func` is a C callback.
*
* A function object is JS object having the Function prototype that holds a
* cfunction value in a hidden property.
*
* The function object will have a `prototype` property holding an object that
* will be used as the prototype of objects created when calling the function
* with the `new` operator.
*/
v7_val_t v7_mk_function(struct v7 *, v7_cfunction_t *func);
/*
* Make f a JS function with specified prototype `proto`, so that the resulting
* function is better suited for the usage as a constructor.
*/
v7_val_t v7_mk_function_with_proto(struct v7 *v7, v7_cfunction_t *f,
v7_val_t proto);
/*
* Make a JS value that holds C/C++ callback pointer.
*
* CAUTION: This is a low-level function value. It's not a real object and
* cannot hold user defined properties. You should use `v7_mk_function` unless
* you know what you're doing.
*/
v7_val_t v7_mk_cfunction(v7_cfunction_t *func);
/*
* Returns true if given value is callable (i.e. it's either a JS function or
* cfunction)
*/
int v7_is_callable(struct v7 *v7, v7_val_t v);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_FUNCTION_PUBLIC_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/regexp_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === RegExp
*/
#ifndef CS_V7_SRC_REGEXP_PUBLIC_H_
#define CS_V7_SRC_REGEXP_PUBLIC_H_
/* Amalgamated: #include "v7/src/core_public.h" */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*
* Make RegExp object.
* `regex`, `regex_len` specify a pattern, `flags` and `flags_len` specify
* flags. Both utf8 encoded. For example, `regex` is `(.+)`, `flags` is `gi`.
* If `regex_len` is ~0, `regex` is assumed to be NUL-terminated and
* `strlen(regex)` is used.
*/
WARN_UNUSED_RESULT
enum v7_err v7_mk_regexp(struct v7 *v7, const char *regex, size_t regex_len,
const char *flags, size_t flags_len, v7_val_t *res);
/* Returns true if given value is a JavaScript RegExp object*/
int v7_is_regexp(struct v7 *v7, v7_val_t v);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_REGEXP_PUBLIC_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/conversion_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Conversion
*/
#ifndef CS_V7_SRC_CONVERSION_PUBLIC_H_
#define CS_V7_SRC_CONVERSION_PUBLIC_H_
/* Amalgamated: #include "v7/src/core_public.h" */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/* Stringify mode, see `v7_stringify()` and `v7_stringify_throwing()` */
enum v7_stringify_mode {
V7_STRINGIFY_DEFAULT,
V7_STRINGIFY_JSON,
V7_STRINGIFY_DEBUG,
};
/*
* Generate string representation of the JavaScript value `val` into a buffer
* `buf`, `len`. If `len` is too small to hold a generated string,
* `v7_stringify()` allocates required memory. In that case, it is caller's
* responsibility to free the allocated buffer. Generated string is guaranteed
* to be 0-terminated.
*
* Available stringification modes are:
*
* - `V7_STRINGIFY_DEFAULT`:
* Convert JS value to string, using common JavaScript semantics:
* - If value is an object:
* - call `toString()`;
* - If `toString()` returned non-primitive value, call `valueOf()`;
* - If `valueOf()` returned non-primitive value, throw `TypeError`.
* - Now we have a primitive, and if it's not a string, then stringify it.
*
* - `V7_STRINGIFY_JSON`:
* Generate JSON output
*
* - `V7_STRINGIFY_DEBUG`:
* Mostly like JSON, but will not omit non-JSON objects like functions.
*
* Example code:
*
* char buf[100], *p;
* p = v7_stringify(v7, obj, buf, sizeof(buf), V7_STRINGIFY_DEFAULT);
* printf("JSON string: [%s]\n", p);
* if (p != buf) {
* free(p);
* }
*/
char *v7_stringify(struct v7 *v7, v7_val_t v, char *buf, size_t len,
enum v7_stringify_mode mode);
/*
* Like `v7_stringify()`, but "returns" value through the `res` pointer
* argument. `res` must not be `NULL`.
*
* Caller should check the error code returned, and if it's something other
* than `V7_OK`, perform cleanup and return this code further.
*/
WARN_UNUSED_RESULT
enum v7_err v7_stringify_throwing(struct v7 *v7, v7_val_t v, char *buf,
size_t size, enum v7_stringify_mode mode,
char **res);
/*
* A shortcut for `v7_stringify()` with `V7_STRINGIFY_JSON`
*/
#define v7_to_json(a, b, c, d) v7_stringify(a, b, c, d, V7_STRINGIFY_JSON)
/* Returns true if given value evaluates to true, as in `if (v)` statement. */
int v7_is_truthy(struct v7 *v7, v7_val_t v);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_CONVERSION_PUBLIC_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/exec_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Execution of JavaScript code
*/
#ifndef CS_V7_SRC_EXEC_PUBLIC_H_
#define CS_V7_SRC_EXEC_PUBLIC_H_
/* Amalgamated: #include "v7/src/core_public.h" */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*
* Execute JavaScript `js_code`. The result of evaluation is stored in
* the `result` variable.
* The code can be either a JavaScript source or a precompiled bytecode.
*
* Return:
*
* - V7_OK on success. `result` contains the result of execution.
* - V7_SYNTAX_ERROR if `js_code` in not a valid code. `result` is undefined.
* - V7_EXEC_EXCEPTION if `js_code` threw an exception. `result` stores
* an exception object.
* - V7_AST_TOO_LARGE if `js_code` contains an AST segment longer than 16 bit.
* `result` is undefined. To avoid this error, build V7 with V7_LARGE_AST.
*/
WARN_UNUSED_RESULT
enum v7_err v7_exec(struct v7 *v7, const char *js_code, v7_val_t *result);
/*
* Options for `v7_exec_opt()`. To get default options, like `v7_exec()` uses,
* just zero out this struct.
*/
struct v7_exec_opts {
/* Filename, used for stack traces only */
const char *filename;
/*
* Object to be used as `this`. Note: when it is zeroed out, i.e. it's a
* number `0`, the `undefined` value is assumed. It means that it's
* impossible to actually use the number `0` as `this` object, but it makes
* little sense anyway.
*/
v7_val_t this_obj;
/* Whether the given `js_code` should be interpreted as JSON, not JS code */
unsigned is_json : 1;
};
/*
* Customizable version of `v7_exec()`: allows to specify various options, see
* `struct v7_exec_opts`.
*/
enum v7_err v7_exec_opt(struct v7 *v7, const char *js_code,
const struct v7_exec_opts *opts, v7_val_t *res);
/*
* Like v7_exec but it expects an explicit length instead of treating the code
* as a null terminated string.
*
* The code can be either a JS source or a precompiled bytecode.
*/
WARN_UNUSED_RESULT
enum v7_err v7_exec_buf(struct v7 *v7, const char *js_code, size_t len,
v7_val_t *result);
/*
* Same as `v7_exec()`, but loads source code from `path` file.
*/
WARN_UNUSED_RESULT
enum v7_err v7_exec_file(struct v7 *v7, const char *path, v7_val_t *result);
/*
* Parse `str` and store corresponding JavaScript object in `res` variable.
* String `str` should be '\0'-terminated.
* Return value and semantic is the same as for `v7_exec()`.
*/
WARN_UNUSED_RESULT
enum v7_err v7_parse_json(struct v7 *v7, const char *str, v7_val_t *res);
/*
* Same as `v7_parse_json()`, but loads JSON string from `path`.
*/
WARN_UNUSED_RESULT
enum v7_err v7_parse_json_file(struct v7 *v7, const char *path, v7_val_t *res);
#if !defined(V7_NO_COMPILER)
/*
* Compile JavaScript code `js_code` into the byte code and write generated
* byte code into opened file stream `fp`. If `generate_binary_output` is 0,
* then generated byte code is in human-readable text format. Otherwise, it is
* in the binary format, suitable for execution by V7 instance.
* NOTE: `fp` must be a valid, opened, writable file stream.
*/
WARN_UNUSED_RESULT
enum v7_err v7_compile(const char *js_code, int generate_binary_output,
int use_bcode, FILE *fp);
#endif /* V7_NO_COMPILER */
/*
* Call function `func` with arguments `args`, using `this_obj` as `this`.
* `args` should be an array containing arguments or `undefined`.
*
* `res` can be `NULL` if return value is not required.
*/
WARN_UNUSED_RESULT
enum v7_err v7_apply(struct v7 *v7, v7_val_t func, v7_val_t this_obj,
v7_val_t args, v7_val_t *res);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_EXEC_PUBLIC_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/exceptions_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Exceptions
*/
#ifndef CS_V7_SRC_EXCEPTIONS_PUBLIC_H_
#define CS_V7_SRC_EXCEPTIONS_PUBLIC_H_
/* Amalgamated: #include "v7/src/core_public.h" */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/* Throw an exception with an already existing value. */
WARN_UNUSED_RESULT
enum v7_err v7_throw(struct v7 *v7, v7_val_t v);
/*
* Throw an exception with given formatted message.
*
* Pass "Error" as typ for a generic error.
*/
WARN_UNUSED_RESULT
enum v7_err v7_throwf(struct v7 *v7, const char *typ, const char *err_fmt, ...);
/*
* Rethrow the currently thrown object. In fact, it just returns
* V7_EXEC_EXCEPTION.
*/
WARN_UNUSED_RESULT
enum v7_err v7_rethrow(struct v7 *v7);
/*
* Returns the value that is being thrown at the moment, or `undefined` if
* nothing is being thrown. If `is_thrown` is not `NULL`, it will be set
* to either 0 or 1, depending on whether something is thrown at the moment.
*/
v7_val_t v7_get_thrown_value(struct v7 *v7, unsigned char *is_thrown);
/* Clears currently thrown value, if any. */
void v7_clear_thrown_value(struct v7 *v7);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_EXCEPTIONS_PUBLIC_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/gc_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Garbage Collector
*/
#ifndef CS_V7_SRC_GC_PUBLIC_H_
#define CS_V7_SRC_GC_PUBLIC_H_
/* Amalgamated: #include "v7/src/core_public.h" */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
#if V7_ENABLE__Memory__stats
/* Heap metric id, see `v7_heap_stat()` */
enum v7_heap_stat_what {
V7_HEAP_STAT_HEAP_SIZE,
V7_HEAP_STAT_HEAP_USED,
V7_HEAP_STAT_STRING_HEAP_RESERVED,
V7_HEAP_STAT_STRING_HEAP_USED,
V7_HEAP_STAT_OBJ_HEAP_MAX,
V7_HEAP_STAT_OBJ_HEAP_FREE,
V7_HEAP_STAT_OBJ_HEAP_CELL_SIZE,
V7_HEAP_STAT_FUNC_HEAP_MAX,
V7_HEAP_STAT_FUNC_HEAP_FREE,
V7_HEAP_STAT_FUNC_HEAP_CELL_SIZE,
V7_HEAP_STAT_PROP_HEAP_MAX,
V7_HEAP_STAT_PROP_HEAP_FREE,
V7_HEAP_STAT_PROP_HEAP_CELL_SIZE,
V7_HEAP_STAT_FUNC_AST_SIZE,
V7_HEAP_STAT_BCODE_OPS_SIZE,
V7_HEAP_STAT_BCODE_LIT_TOTAL_SIZE,
V7_HEAP_STAT_BCODE_LIT_DESER_SIZE,
V7_HEAP_STAT_FUNC_OWNED,
V7_HEAP_STAT_FUNC_OWNED_MAX
};
/* Returns a given heap statistics */
int v7_heap_stat(struct v7 *v7, enum v7_heap_stat_what what);
#endif
/*
* Perform garbage collection.
* Pass true to full in order to reclaim unused heap back to the OS.
*/
void v7_gc(struct v7 *v7, int full);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_GC_PUBLIC_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/util_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Utility functions
*/
#ifndef CS_V7_SRC_UTIL_PUBLIC_H_
#define CS_V7_SRC_UTIL_PUBLIC_H_
/* Amalgamated: #include "v7/src/core_public.h" */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/* Output a string representation of the value to stdout.
* V7_STRINGIFY_DEBUG mode is used. */
void v7_print(struct v7 *v7, v7_val_t v);
/* Output a string representation of the value to stdout followed by a newline.
* V7_STRINGIFY_DEBUG mode is used. */
void v7_println(struct v7 *v7, v7_val_t v);
/* Output a string representation of the value to a file.
* V7_STRINGIFY_DEBUG mode is used. */
void v7_fprint(FILE *f, struct v7 *v7, v7_val_t v);
/* Output a string representation of the value to a file followed by a newline.
* V7_STRINGIFY_DEBUG mode is used. */
void v7_fprintln(FILE *f, struct v7 *v7, v7_val_t v);
/* Output stack trace recorded in the exception `e` to file `f` */
void v7_fprint_stack_trace(FILE *f, struct v7 *v7, v7_val_t e);
/* Output error object message and possibly stack trace to f */
void v7_print_error(FILE *f, struct v7 *v7, const char *ctx, v7_val_t e);
#if V7_ENABLE__Proxy
struct v7_property;
/*
* C callback, analogue of JS callback `getOwnPropertyDescriptor()`.
* Callbacks of this type are used for C API only, see `m7_mk_proxy()`.
*
* `name` is the name of the property, and the function should fill `attrs` and
* `value` with the property data. Before this callback is called, `attrs` is
* set to 0, and `value` is `V7_UNDEFINED`.
*
* It should return non-zero if the property should be considered existing, or
* zero otherwise.
*
* You can inspect the property attributes with the `V7_PROP_ATTR_IS_*` macros.
*/
typedef int(v7_get_own_prop_desc_cb_t)(struct v7 *v7, v7_val_t target,
v7_val_t name, v7_prop_attr_t *attrs,
v7_val_t *value);
/* Handler for `v7_mk_proxy()`; each item is a cfunction */
typedef struct {
v7_cfunction_t *get;
v7_cfunction_t *set;
v7_cfunction_t *own_keys;
v7_get_own_prop_desc_cb_t *get_own_prop_desc;
} v7_proxy_hnd_t;
/*
* Create a Proxy object, see:
* https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Proxy
*
* Only two traps are implemented so far: `get()` and `set()`. Note that
* `Object.defineProperty()` bypasses the `set()` trap.
*
* If `target` is not an object, the empty object will be used, so it's safe
* to pass `V7_UNDEFINED` as `target`.
*/
v7_val_t v7_mk_proxy(struct v7 *v7, v7_val_t target,
const v7_proxy_hnd_t *handler);
#endif /* V7_ENABLE__Proxy */
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_UTIL_PUBLIC_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/main_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === v7 main()
*/
#ifndef CS_V7_SRC_MAIN_PUBLIC_H_
#define CS_V7_SRC_MAIN_PUBLIC_H_
/* Amalgamated: #include "v7/src/core_public.h" */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*
* V7 executable main function.
*
* There are various callbacks available:
*
* `pre_freeze_init()` and `pre_init()` are optional intialization functions,
* aimed to export any extra functionality into vanilla v7 engine. They are
* called after v7 initialization, before executing given files or inline
* expressions. `pre_freeze_init()` is called before "freezing" v7 state;
* whereas `pre_init` called afterwards.
*
* `post_init()`, if provided, is called after executing files and expressions,
* before destroying v7 instance and exiting.
*/
int v7_main(int argc, char *argv[], void (*pre_freeze_init)(struct v7 *),
void (*pre_init)(struct v7 *), void (*post_init)(struct v7 *));
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_MAIN_PUBLIC_H_ */
#endif /* V7_EXPORT_INTERNAL_HEADERS */
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/weimingtom/v7.git
git@gitee.com:weimingtom/v7.git
weimingtom
v7
v7
master

搜索帮助